Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

custom decorator #713

Open
GreenRover opened this issue Jul 25, 2016 · 1 comment
Open

custom decorator #713

GreenRover opened this issue Jul 25, 2016 · 1 comment

Comments

@GreenRover
Copy link

Hello, i extend Zend_Form and do in _construct()

                $this->addElementPrefixPath('Example_Form_Decorator', 'Example/Form/Decorator/, 'DECORATOR');
                $this->addDisplayGroupPrefixPath('Example_Form_Decorator', 'Example/Form/Decorator/',  'DECORATOR');

And in form:

        $permissions = new Zend_Form_Element_Text('xxxx');
        $permissions->setLabel('xxxx')
                ->addDecorator('Accordion'); // Custom decorator.

This work well in 1.11.11 but gives a "not existing decorator exception in 1.12.18

The problem is you changed Zend_Form::addElement()

Now you call getDecorators() before you do addPrefixPaths()

Here is a fix:

diff -Naur org/Zend/Form.php fixed/Zend/Form.php
--- org/Zend/Form.php   2016-07-14 15:27:04.060777649 +0200
+++ fixed/Zend/Form.php 2016-07-14 15:27:48.000000000 +0200
@@ -1048,18 +1048,20 @@
                 $prefixPaths = array_merge($prefixPaths, $this->_elementPrefixPaths);
             }

-            if (is_array($this->_elementDecorators)
-                && 0 == count($element->getDecorators())
-            ) {
-                $element->setDecorators($this->_elementDecorators);
-            }
-
             if (null === $name) {
                 $name = $element->getName();
             }

             $this->_elements[$name] = $element;
             $this->_elements[$name]->addPrefixPaths($prefixPaths);
+
+
+            if (is_array($this->_elementDecorators)
+                && 0 == count($this->_elements[$name]->getDecorators())
+            ) {
+                $this->_elements[$name]->setDecorators($this->_elementDecorators);
+            }
+
         } else {
             require_once 'Zend/Form/Exception.php';
             throw new Zend_Form_Exception(

@froschdesign
Copy link
Member

We are sorry, but ZF1 reaches its End of Life (EOL).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants