Browse Source

merge r25116 to release-1.12

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25117 44c647ce-9c0f-0410-b52a-842ac1e357ba
rob 13 năm trước cách đây
mục cha
commit
19f7c3f45b
2 tập tin đã thay đổi với 39 bổ sung13 xóa
  1. 10 13
      library/Zend/Form.php
  2. 29 0
      tests/Zend/Form/FormTest.php

+ 10 - 13
library/Zend/Form.php

@@ -1025,19 +1025,6 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
                 throw new Zend_Form_Exception('Elements specified by string must have an accompanying name');
             }
 
-            if (is_array($this->_elementDecorators)) {
-                if (null === $options) {
-                    $options = array('decorators' => $this->_elementDecorators);
-                } elseif ($options instanceof Zend_Config) {
-                    $options = $options->toArray();
-                }
-                if (is_array($options)
-                    && !array_key_exists('decorators', $options)
-                ) {
-                    $options['decorators'] = $this->_elementDecorators;
-                }
-            }
-
             $this->_elements[$name] = $this->createElement($element, $name, $options);
         } elseif ($element instanceof Zend_Form_Element) {
             $prefixPaths              = array();
@@ -1101,12 +1088,22 @@ class Zend_Form implements Iterator, Countable, Zend_Validate_Interface
 
         if ((null === $options) || !is_array($options)) {
             $options = array('prefixPath' => $prefixPaths);
+
+            if (is_array($this->_elementDecorators)) {
+                $options['decorators'] = $this->_elementDecorators;
+            }
         } elseif (is_array($options)) {
             if (array_key_exists('prefixPath', $options)) {
                 $options['prefixPath'] = array_merge($prefixPaths, $options['prefixPath']);
             } else {
                 $options['prefixPath'] = $prefixPaths;
             }
+
+            if (is_array($this->_elementDecorators)
+                && !array_key_exists('decorators', $options)
+            ) {
+                $options['decorators'] = $this->_elementDecorators;
+            }
         }
 
         $class = $this->getPluginLoader(self::ELEMENT)->load($type);

+ 29 - 0
tests/Zend/Form/FormTest.php

@@ -4596,6 +4596,35 @@ class Zend_Form_FormTest extends PHPUnit_Framework_TestCase
             $this->assertContains('Foo', $paths[0]);
         }
     }
+
+    /**
+     * @group ZF-8942
+     */
+    public function testCreateElementIncludesElementDecorators()
+    {
+        // Init form
+        $form = new Zend_Form();
+        $form->setElementDecorators(
+            array(
+                 new Zend_Form_Decorator_ViewHelper,
+                 new Zend_Form_Decorator_Label,
+            )
+        );
+        $element = $form->createElement('text', 'foo');
+
+        //  Test
+        $expected = array(
+            'Zend_Form_Decorator_ViewHelper',
+            'Zend_Form_Decorator_Label',
+        );
+
+        $actual = array();
+        foreach ($element->getDecorators() as $decorator) {
+            $actual[] = get_class($decorator);
+        }
+
+        $this->assertEquals($expected, $actual);
+    }
 }
 
 class Zend_Form_FormTest_DisplayGroup extends Zend_Form_DisplayGroup