ZF-8882: Propagate option 'disableTranslator' from Zend_Form_Element to it's validators

Description

When setting the option 'disableTranslator' to true in any Zend_Form_Element, it isn't being propagated to its validators. At least not to Zend_Validate_NotEmpty (I haven't tested other validators yet).

I don't know if this is done deliberate or not, but I would expect setting 'disableTranslator' to true will cause the entire Zend_Form_Element not to translate anything (including validators and other plugins that are loaded).

I think the source of this problem lies in the way the option 'disableTranslator' is handled by Zend_Form_Element: By setting it to true, the translator passed to the validators will be 'null' (in stead of an instance of Zend_Translate(_Adapter)). But when the validator tries to use its translator (which is 'null'), it will load the default translator and things will still be translated.

In my opinion we need to propagate the option 'disableTranslator' itself (not simulate it by passing 'null' as translator as it doesn't completely disable translation).

I've tried to work around this "problem" by setting the option 'autoInsertNotEmptyValidator' to false and manually prepend Zend_Validate_NotEmpty (with 'disableTranslator' in its options) to Zend_Form_Element-s validators. This way the option 'disableTranslator' will be set on Zend_Validate_NotEmpty itself (and doesn't have to be propagated from Zend_Form_Element).

This also has no effect! (Zend_Validate_NotEmpty will still translate error-messages.)

I've figured out the source of this second "problem": Zend_Validate_NotEmpty doesn't have a constructor: When the Zend_Form_Element loads its validators, it will instantiate them using the options as constructor-arguments. But because Zend_Validate_NotEmpty doesn't have a constructor, no options will be set.

I've worked around this second "problem" by creating a My_Validate_NotEmpty (which extends Zend_Validate_NotEmpty). I've put a constructor in it which takes 'disableTranslator' as an argument and sets the option.

At first glance this seems like a neat solution, no hacks in existing Zend Framework files were needed and the adjustment I made in My_Validate_NotEmpty is very very small.

But I do think this solution defeats the whole purpose of the option 'disableTranslator' in Zend_Form_Element.

Comments

I've also tested this in the latest stable release: 1.9.7

This "problem" also exists between Zend_Form_Element_Multi and it's 'multiOptions'.

Fixed with r20705