Issues

ZF-12387: Zend Form Element objects added via addElement() don't get default element Decorators

Issue Type: Bug Created: 2012-08-24T16:12:27.000+0000 Last Updated: 2013-01-17T15:18:56.000+0000 Status: Resolved Fix version(s): - 1.12.2 (25/Feb/13)

Reporter: Sam Adams (samadams83) Assignee: Frank Brückner (frosch) Tags: - Zend_Form

Related issues: - ZF-8942

Attachments: - Form.php.patch

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.

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

<pre class="highlight">
$element = new Zend_Form_Element_Text('foo');
$element->setDecorators(array('ViewHelper', 'Label');

$form->addElement($element);

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)

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