Issues

ZF-8942: Zend_Form::createElement() doesn't load default decorators -- simple fix included!

Description

Per the API docs, Zend_Form::createElement() should load the default decorators set by Zend_Form::setElementDecorators(). It does not...

Reproduce:


<?php
class TestCreateElementForm extends Zend_Form
{
    public function init()
    {
        // Sets default decorators
        $this->setElementDecorators(array('Label'));

        // Add an element directly to the form 
        $this->addElement('text', 'element_1');
        print_r($this->getElement('element_1')->getDecorators()); // This works!

        // This doesn't set the decorators
        $element_2 = $this->createElement('text', 'element_2');
        print_r($element_2->getDecorators()); // Does NOT work

        exit;
    }
}
?>

Simple Fix: Move lines 996-10007 in Zend_Form::addElement() to Zend_Form::createElement() line 1066. This won't affect addElement() setting of default decorators because it calls createElement() also.

Comments

This issue is still a problem. The docblock on createElement states that it should create a form element with the default decorators but it does not actually produce that result.

Patch and unit test added.

Is this a BC break? i.e. would someone expect createElement to not set default decorators?

{quote}would someone expect createElement to not set default decorators?{quote} I will expect the described behaviour: ;) {quote}Acts as a factory for creating elements. Elements created with this method will not be attached to the form, but will contain element settings as specified in the form object (including plugin loader prefix paths, default decorators, etc.).{quote} http://framework.zend.com/apidoc/1.12/…

Patch applied to trunk (25116) and release-1.12 (25117)