Issues

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

Issue Type: Bug Created: 2010-03-21T04:28:59.000+0000 Last Updated: 2010-03-23T14:29:39.000+0000 Status: Resolved Fix version(s): - 1.10.3 (01/Apr/10)

Reporter: Rob Allen (rob) Assignee: Rob Allen (rob) Tags: - Zend_Form

Related issues: Attachments:

Description

Zend_Form's isValid() does this:

<pre class="highlight">
$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:

<pre class="highlight">
$ 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

Posted by Rob Allen (rob) on 2010-03-21T04:32:01.000+0000

Looking at isValidPartial(), the correct patch is:

<pre class="highlight">
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 {

Posted by Rob Allen (rob) on 2010-03-21T04:39:57.000+0000

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

Posted by Christian Albrecht (alab) on 2010-03-23T11:01:17.000+0000

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]?

Posted by Christian Albrecht (alab) on 2010-03-23T11:11:50.000+0000

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

Posted by Rob Allen (rob) on 2010-03-23T12:57:04.000+0000

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

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts