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

Issue Type: Improvement Created: 2010-01-20T04:25:56.000+0000 Last Updated: 2010-01-27T12:47:00.000+0000 Status: Resolved Fix version(s): - 1.10.1 (10/Feb/10)

Reporter: Jasper N. Brouwer (j4pp13) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

  • Zend_Validate

Related issues: Attachments:


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.


Posted by Jasper N. Brouwer (j4pp13) on 2010-01-26T06:33:42.000+0000

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'.

Posted by Thomas Weidner (thomas) on 2010-01-27T12:47:00.000+0000

Fixed with r20705

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.