Issues

ZF-12405: Zend_Form_Element Need an option to set default decorators globally

Description

Now when creating a Form Element, if there is no default decorators are specified, the following code add default decorators


$this->addDecorator('ViewHelper')
 ->addDecorator('Errors')
->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
->addDecorator('HtmlTag', array(
    'tag' => 'dd',
      'id'  => array('callback' => array(get_class($this), 'resolveElementId'))
))->addDecorator('Label', array('tag' => 'dt'));

Need an option to set default Decorators globally rather than current option, Some thing like a static function to set default decorators.

Comments

I already tried this function. Zend_Form::setElementDecorators() function will remove all current decorators in element. and we have call it after adding all form elements. and add particular decorator for each decorators. If we have more forms a global option will be better.

Here is a simple example:


$form = new Zend_Form();
$form->setDecorators(
    array(
        'FormElements',
        'Form'
    )
);
$form->setElementDecorators(
    array(
        'Label',
    )
);

$form->addElement(
    'text',
    'foo',
    array(
        'label' => 'Foo',
    )
);
$form->addElement(
    'text',
    'bar',
    array(
        'label' => 'Bar',
    )
);
$form->addElement(
    'submit',
    'baz',
    array(
        'label'      => 'Baz',
        'decorators' => array(
            'ViewHelper',
        ),
    )
);

echo $form->render(new Zend_View());


    Foo
    Bar
    

Where is the problem?