mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
form: Correctly set our default element decorators
This commit is contained in:
parent
fa96a1cbbe
commit
2956d9e342
@ -5,6 +5,7 @@
|
|||||||
namespace Icinga\Web;
|
namespace Icinga\Web;
|
||||||
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
|
use Zend_Config;
|
||||||
use Zend_Form;
|
use Zend_Form;
|
||||||
use Zend_View_Interface;
|
use Zend_View_Interface;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
@ -81,6 +82,19 @@ class Form extends Zend_Form
|
|||||||
*/
|
*/
|
||||||
protected $uidElementName = 'formUID';
|
protected $uidElementName = 'formUID';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default element decorators
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $defaultElementDecorators = array(
|
||||||
|
'ViewHelper',
|
||||||
|
'Errors',
|
||||||
|
array('Description', array('tag' => 'span', 'class' => 'description')),
|
||||||
|
'Label',
|
||||||
|
array('HtmlTag', array('tag' => 'div'))
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new form
|
* Create a new form
|
||||||
*
|
*
|
||||||
@ -105,16 +119,6 @@ class Form extends Zend_Form
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,23 +421,35 @@ class Form extends Zend_Form
|
|||||||
/**
|
/**
|
||||||
* Create a new element
|
* Create a new element
|
||||||
*
|
*
|
||||||
* Additionally, all structural form element decorators by Zend are replaced with our own ones.
|
* Icinga Web 2 loads its own default element decorators. For loading Zend's default element decorators set the
|
||||||
|
* `disableLoadDefaultDecorators' option to any other value than `true'. For loading custom element decorators use
|
||||||
|
* the 'decorators' option.
|
||||||
*
|
*
|
||||||
* @param string $type String element type
|
* @param string $type String element type
|
||||||
* @param string $name The name of the element to add
|
* @param string $name The name of the element to add
|
||||||
* @param array $options The options for the element
|
* @param mixed $options The options for the element
|
||||||
*
|
*
|
||||||
* @return Zend_Form_Element
|
* @return Zend_Form_Element
|
||||||
*
|
*
|
||||||
* @see Zend_Form::createElement()
|
* @see Form::$defaultElementDecorators For Icinga Web 2's default element decorators.
|
||||||
*/
|
*/
|
||||||
public function createElement($type, $name, $options = null)
|
public function createElement($type, $name, $options = null)
|
||||||
{
|
{
|
||||||
if (is_array($options) && ! isset($options['disableLoadDefaultDecorators'])) {
|
if ($options !== null) {
|
||||||
$options['disableLoadDefaultDecorators'] = true;
|
if ($options instanceof Zend_Config) {
|
||||||
|
$options = $options->toArray();
|
||||||
|
}
|
||||||
|
if (! isset($options['decorators'])
|
||||||
|
&& ! array_key_exists('disabledLoadDefaultDecorators', $options)
|
||||||
|
) {
|
||||||
|
$options['decorators'] = static::$defaultElementDecorators;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$options = array('decorators' => static::$defaultElementDecorators);
|
||||||
}
|
}
|
||||||
|
|
||||||
$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
|
||||||
$class = $el->getAttrib('class');
|
$class = $el->getAttrib('class');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user