lib/form: Fix default element decorators but breaking noscript layout

Replaced `ElementWrapper' and `HelpText' with Zend's `HtmlTag' and `Label' respectively.

Instances of Zend_Form_Element returned by `Form::createElements()' now receive our desired default decorators.

refs #5525
This commit is contained in:
Eric Lippmann 2014-09-02 15:23:07 +02:00
parent 8478ef3fce
commit d4c4ab7b2c

View File

@ -99,7 +99,15 @@ class Form extends Zend_Form
if ($this->onSuccess !== null && false === is_callable($this->onSuccess)) { if ($this->onSuccess !== null && false === is_callable($this->onSuccess)) {
throw new LogicException('The option `onSuccess\' is not callable'); throw new LogicException('The option `onSuccess\' is not callable');
} }
if (! isset($options['elementDecorators'])) {
$options['elementDecorators'] = array(
'ViewHelper',
'Errors',
array('Description', array('tag' => 'span', 'class' => 'description')),
'Label',
array('HtmlTag', array('tag' => 'div'))
);
}
parent::__construct($options); parent::__construct($options);
} }
@ -334,7 +342,11 @@ class Form extends Zend_Form
'btn_submit', 'btn_submit',
array( array(
'ignore' => true, 'ignore' => true,
'label' => $this->submitLabel 'label' => $this->submitLabel,
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'div'))
)
) )
); );
} }
@ -357,18 +369,11 @@ class Form extends Zend_Form
*/ */
public function createElement($type, $name, $options = null) public function createElement($type, $name, $options = null)
{ {
if (is_array($options) && ! isset($options['disableLoadDefaultDecorators'])) {
$options['disableLoadDefaultDecorators'] = true;
}
$el = parent::createElement($type, $name, $options); $el = parent::createElement($type, $name, $options);
if ($el && $el->getAttrib('autosubmit')) {
if ($el) {
if (strpos(strtolower(get_class($el)), 'hidden') !== false) {
$el->setDecorators(array('ViewHelper'));
} else {
$el->removeDecorator('HtmlTag');
$el->removeDecorator('Label');
$el->removeDecorator('DtDdWrapper');
if ($el->getAttrib('autosubmit')) {
// Need to add this decorator first or it interferes with the other's two HTML otherwise
$el->addDecorator(new NoScriptApply()); // Non-JS environments $el->addDecorator(new NoScriptApply()); // Non-JS environments
$class = $el->getAttrib('class'); $class = $el->getAttrib('class');
if (is_array($class)) { if (is_array($class)) {
@ -381,12 +386,6 @@ class Form extends Zend_Form
$el->setAttrib('class', $class); // JS environments $el->setAttrib('class', $class); // JS environments
unset($el->autosubmit); unset($el->autosubmit);
} }
$el->addDecorator(new ElementWrapper());
$el->addDecorator(new HelpText());
}
}
return $el; return $el;
} }
@ -556,7 +555,6 @@ class Form extends Zend_Form
if ($this->loadDefaultDecoratorsIsDisabled()) { if ($this->loadDefaultDecoratorsIsDisabled()) {
return $this; return $this;
} }
$decorators = $this->getDecorators(); $decorators = $this->getDecorators();
if (empty($decorators)) { if (empty($decorators)) {
if ($this->viewScript) { if ($this->viewScript) {
@ -565,12 +563,11 @@ class Form extends Zend_Form
'form' => $this 'form' => $this
)); ));
} else { } else {
$this->addDecorator('FormElements') $this
//->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')) ->addDecorator('FormElements')
->addDecorator('Form'); ->addDecorator('Form');
} }
} }
return $this; return $this;
} }