Issues

ZF-9494: Zend_Form::isValid() overrides translator set on an element

Description

Zend_Form's isValid() does this:


$translator = $this->getTranslator();
// ...
foreach($this->getElements() as $key => $element) {
    $element->setTranslator($translator);
// etc
   

This means that if you've put a translator onto an element, it is overriden by the translator attached to the form. If there is no translator attached to the form, then the translator attached to the element is removed!

Suggested patch:


$ svn diff library/Zend/Form.php
Index: library/Zend/Form.php
===================================================================
--- library/Zend/Form.php   (revision 21590)
+++ library/Zend/Form.php   (working copy)
@@ -2031,7 +2031,9 @@
         }
 
         foreach ($this->getElements() as $key => $element) {
-            $element->setTranslator($translator);
+            if ($translator) {
+                $element->setTranslator($translator);
+            }
             if (!isset($data[$key])) {
                 $valid = $element->isValid(null, $data) && $valid;
             } else {

Comments

Looking at isValidPartial(), the correct patch is:


Index: library/Zend/Form.php
===================================================================
--- library/Zend/Form.php   (revision 21590)
+++ library/Zend/Form.php   (working copy)
@@ -2031,7 +2031,9 @@
         }
 
         foreach ($this->getElements() as $key => $element) {
-            $element->setTranslator($translator);
+            if (null !== $translator) {
+                $element->setTranslator($translator);
+            }
             if (!isset($data[$key])) {
                 $valid = $element->isValid(null, $data) && $valid;
             } else {

Fixed on trunk r21591. Fixed on release-1.10 branch r21593 (http://framework.zend.com/code/changelog/…)

Sorry, Rob, it seems to me you missed the point. Because when setting a translator on Form Level in addition to setting a translator on an Element, the Forms Translator will neverless overwrite the Elements Translator.

Would you mind to have a look at [ZF-9364]?

Duh, or did I? Is the Forms Translator supposed to be more mightful than the Translators on Element Level?

Christian,

You're right in that if there is a forms level translator, it should override the element one. It has to be like that in order to preserve B/C.

This issue is concerned with the case when you don't have a forms level one but do have an element level. Prior to this path, the element level was was removed even though there was no forms level translator to replace it.

Regards,

Rob...