ZF-12387: Zend Form Element objects added via addElement() don't get default element Decorators
Description
When adding an element to a form via $form->addElement(...) it wont get the default element decorators if the argument is an Zend_Form_Element object. E.g.
$form = new Zend_Form();
$form->setElementDecorators(array('viewHelper','Errors'));
$el = new Zend_Form_Element_Text('foo');
$form->addElement($el);
var_dump($form->getElement('foo')->getDecorators());
//vs
$form->addElement('text','bar');
var_dump($form->getElement('bar')->getDecorators());
Could be linked to: http://framework.zend.com/issues/browse/ZF-8942
Comments
Posted by Frank Brückner (frosch) on 2012-08-24T17:10:37.000+0000
There is a problem:
If we add the element decorators from the form, then we override the current decorators of the element. Bad idea!
Posted by Sam Adams (samadams83) on 2012-08-25T16:13:35.000+0000
I agree that explicitly set decorators should take precedence over the form element defaults, but it makes sense to be able to change the default set of decorators that are used for elements without explicitly set decorators. The alternative is (if you want to use the object method) to add the decorators to each element every time, which is wasteful. Is there a way of inspecting the element object to see if decorators were set, and if not, set the form default?
Posted by shamseer (shamseerss) on 2012-09-05T12:51:23.000+0000
when an element is created by this code $el = new Zend_Form_Element_Text('foo');
default decorators(ViewHelper, Errors,....) added by default, if decorator option is not specified in the constructor.
Better to create your own factory for elements creation
Posted by Frank Brückner (frosch) on 2012-09-05T13:00:51.000+0000
@[~samadams83] {quote}Is there a way of inspecting the element object to see if decorators were set, and if not, set the form default?{quote} Yes. I will look into it.
Posted by Frank Brückner (frosch) on 2013-01-17T13:49:36.000+0000
Patch and unit tests added.
Posted by Rob Allen (rob) on 2013-01-17T14:28:26.000+0000
Patch looks good to me. Please commit.
Posted by Frank Brückner (frosch) on 2013-01-17T14:45:16.000+0000
Fixed on trunk (25222) and release-1.12 (25223)