Add the FormErrors decorator as default decorator for forms

This allows us to use Zend_Form::addError() to show error messages for
the entire form context.

refs #5525
This commit is contained in:
Johannes Meyer 2014-09-02 14:48:37 +02:00
parent 338f549233
commit 539ab91ffa

View File

@ -99,6 +99,7 @@ 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'])) { if (! isset($options['elementDecorators'])) {
$options['elementDecorators'] = array( $options['elementDecorators'] = array(
'ViewHelper', 'ViewHelper',
@ -108,6 +109,7 @@ class Form extends Zend_Form
array('HtmlTag', array('tag' => 'div')) array('HtmlTag', array('tag' => 'div'))
); );
} }
parent::__construct($options); parent::__construct($options);
} }
@ -372,6 +374,7 @@ class Form extends Zend_Form
if (is_array($options) && ! isset($options['disableLoadDefaultDecorators'])) { if (is_array($options) && ! isset($options['disableLoadDefaultDecorators'])) {
$options['disableLoadDefaultDecorators'] = true; $options['disableLoadDefaultDecorators'] = true;
} }
$el = parent::createElement($type, $name, $options); $el = parent::createElement($type, $name, $options);
if ($el && $el->getAttrib('autosubmit')) { if ($el && $el->getAttrib('autosubmit')) {
$el->addDecorator(new NoScriptApply()); // Non-JS environments $el->addDecorator(new NoScriptApply()); // Non-JS environments
@ -386,6 +389,7 @@ class Form extends Zend_Form
$el->setAttrib('class', $class); // JS environments $el->setAttrib('class', $class); // JS environments
unset($el->autosubmit); unset($el->autosubmit);
} }
return $el; return $el;
} }
@ -555,6 +559,7 @@ 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) {
@ -563,11 +568,13 @@ class Form extends Zend_Form
'form' => $this 'form' => $this
)); ));
} else { } else {
$this $this->addDecorator('FormErrors', array('onlyCustomFormErrors' => true))
->addDecorator('FormElements') ->addDecorator('FormElements')
//->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
->addDecorator('Form'); ->addDecorator('Form');
} }
} }
return $this; return $this;
} }