Parcourir la source

ZF-9862: prevent merging of elementsBelongTo after FormElements was called

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22238 44c647ce-9c0f-0410-b52a-842ac1e357ba
alab il y a 15 ans
Parent
commit
f76a4bc725
1 fichiers modifiés avec 42 ajouts et 4 suppressions
  1. 42 4
      library/Zend/Form.php

+ 42 - 4
library/Zend/Form.php

@@ -216,6 +216,11 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
     protected $_view;
     protected $_view;
 
 
     /**
     /**
+     * @var bool
+     */
+    protected $_isRendered = false;
+
+    /**
      * Constructor
      * Constructor
      *
      *
      * Registers form view helper as decorator
      * Registers form view helper as decorator
@@ -967,6 +972,25 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
         return $this->_formOrder;
         return $this->_formOrder;
     }
     }
 
 
+    /**
+     * When calling renderFormElements or render this method
+     * is used to set $_isRendered member to prevent repeatedly
+     * merging belongsTo setting
+     */
+    protected function _setIsRendered()
+    {
+        $this->_isRendered = true;
+        return $this;
+    }
+
+    /**
+     * Get the value of $_isRendered member
+     */
+    protected function _getIsRendered()
+    {
+        return (bool)$this->_isRendered;
+    }
+
     // Element interaction:
     // Element interaction:
 
 
     /**
     /**
@@ -1338,7 +1362,9 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
             $values = $this->_array_replace_recursive($values, $merge);
             $values = $this->_array_replace_recursive($values, $merge);
         }
         }
 
 
-        if (!$suppressArrayNotation && $this->isArray()) {
+        if (!$suppressArrayNotation &&
+            $this->isArray() &&
+            !$this->_getIsRendered()) {
             $values = $this->_attachToArray($values, $this->getElementsBelongTo());
             $values = $this->_attachToArray($values, $this->getElementsBelongTo());
         }
         }
 
 
@@ -1398,7 +1424,10 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
             }
             }
             $values = $this->_array_replace_recursive($values, $merge);
             $values = $this->_array_replace_recursive($values, $merge);
         }
         }
-        if (!$suppressArrayNotation && $this->isArray() && !empty($values)) {
+        if (!$suppressArrayNotation &&
+            $this->isArray() &&
+            !empty($values) &&
+            !$this->_getIsRendered()) {
             $values = $this->_attachToArray($values, $this->getElementsBelongTo());
             $values = $this->_attachToArray($values, $this->getElementsBelongTo());
         }
         }
 
 
@@ -2414,7 +2443,9 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
             $errors = $this->_array_replace_recursive($errors, $merge);
             $errors = $this->_array_replace_recursive($errors, $merge);
         }
         }
 
 
-        if (!$suppressArrayNotation && $this->isArray()) {
+        if (!$suppressArrayNotation &&
+            $this->isArray() &&
+            !$this->_getIsRendered()) {
             $errors = $this->_attachToArray($errors, $this->getElementsBelongTo());
             $errors = $this->_attachToArray($errors, $this->getElementsBelongTo());
         }
         }
 
 
@@ -2473,7 +2504,9 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
             }
             }
         }
         }
 
 
-        if (!$suppressArrayNotation && $this->isArray()) {
+        if (!$suppressArrayNotation &&
+            $this->isArray() &&
+            !$this->_getIsRendered()) {
             $messages = $this->_attachToArray($messages, $this->getElementsBelongTo());
             $messages = $this->_attachToArray($messages, $this->getElementsBelongTo());
         }
         }
 
 
@@ -2800,6 +2833,7 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
             $decorator->setElement($this);
             $decorator->setElement($this);
             $content = $decorator->render($content);
             $content = $decorator->render($content);
         }
         }
+        $this->_setIsRendered();
         return $content;
         return $content;
     }
     }
 
 
@@ -3053,6 +3087,10 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
                 if (0 < count($args)) {
                 if (0 < count($args)) {
                     $seed = array_shift($args);
                     $seed = array_shift($args);
                 }
                 }
+                if ($decoratorName === 'FormElements' ||
+                    $decoratorName === 'PrepareElements') {
+                        $this->_setIsRendered();
+                }
                 return $decorator->render($seed);
                 return $decorator->render($seed);
             }
             }