Merge pull request #3010 from Icinga/bugfix/cant-create-resources-and-command-transports-2998
Bugfix/cant create resources and command transports 2998
This commit is contained in:
commit
04c8892f24
|
@ -19,18 +19,6 @@ use Icinga\Web\Form\Element\CsrfCounterMeasure;
|
||||||
/**
|
/**
|
||||||
* Base class for forms providing CSRF protection, confirmation logic and auto submission
|
* Base class for forms providing CSRF protection, confirmation logic and auto submission
|
||||||
*
|
*
|
||||||
* @method $this setDefaults(array $defaults) {
|
|
||||||
* Use `Form::populate()' for setting default values for elements instead because `Form::setDefaults()' does not
|
|
||||||
* create the form via `Form::create()'.
|
|
||||||
*
|
|
||||||
* Due to a BC introduced with https://github.com/mhujer/zf1/commit/244e3d3f88a363ee0ca49cf63eee31f925f515cd
|
|
||||||
* we cannot override this function without running into a strict standards violation on Zend version 1.12.7.
|
|
||||||
*
|
|
||||||
* @param array $defaults
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* @method \Zend_Form_Element[] getElements() {
|
* @method \Zend_Form_Element[] getElements() {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
* @return \Zend_Form_Element[]
|
* @return \Zend_Form_Element[]
|
||||||
|
@ -1083,6 +1071,21 @@ class Form extends Zend_Form
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* Creates the form if not created yet.
|
||||||
|
*
|
||||||
|
* @param array $values
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDefaults(array $values)
|
||||||
|
{
|
||||||
|
$this->create($values);
|
||||||
|
return parent::setDefaults($values);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populate the elements with the given values
|
* Populate the elements with the given values
|
||||||
*
|
*
|
||||||
|
@ -1102,22 +1105,21 @@ class Form extends Zend_Form
|
||||||
*
|
*
|
||||||
* @param Zend_Form $form
|
* @param Zend_Form $form
|
||||||
* @param array $defaults
|
* @param array $defaults
|
||||||
* @param bool $ignoreDisabled
|
|
||||||
*/
|
*/
|
||||||
protected function preserveDefaults(Zend_Form $form, array & $defaults, $ignoreDisabled = true)
|
protected function preserveDefaults(Zend_Form $form, array & $defaults)
|
||||||
{
|
{
|
||||||
foreach ($form->getElements() as $name => $element) {
|
foreach ($form->getElements() as $name => $element) {
|
||||||
if ((array_key_exists($name, $defaults)
|
if ((array_key_exists($name, $defaults)
|
||||||
&& array_key_exists($name . static::DEFAULT_SUFFIX, $defaults)
|
&& array_key_exists($name . static::DEFAULT_SUFFIX, $defaults)
|
||||||
&& $defaults[$name] === $defaults[$name . static::DEFAULT_SUFFIX])
|
&& $defaults[$name] === $defaults[$name . static::DEFAULT_SUFFIX])
|
||||||
|| (! $ignoreDisabled && $element->getAttrib('disabled'))
|
|| $element->getAttrib('disabled')
|
||||||
) {
|
) {
|
||||||
unset($defaults[$name]);
|
unset($defaults[$name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($form->getSubForms() as $_ => $subForm) {
|
foreach ($form->getSubForms() as $_ => $subForm) {
|
||||||
$this->preserveDefaults($subForm, $defaults, $ignoreDisabled);
|
$this->preserveDefaults($subForm, $defaults);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1144,11 +1146,6 @@ class Form extends Zend_Form
|
||||||
if (($frameUpload = (bool) $request->getUrl()->shift('_frameUpload', false))) {
|
if (($frameUpload = (bool) $request->getUrl()->shift('_frameUpload', false))) {
|
||||||
$this->getView()->layout()->setLayout('wrapped');
|
$this->getView()->layout()->setLayout('wrapped');
|
||||||
}
|
}
|
||||||
|
|
||||||
// To prevent a BC, this is here. The proper fix is to extend populate()
|
|
||||||
// and pass $ignoreDisabled through to preserveDefaults()
|
|
||||||
$this->create($formData)->preserveDefaults($this, $formData, false);
|
|
||||||
|
|
||||||
$this->populate($formData); // Necessary to get isSubmitted() to work
|
$this->populate($formData); // Necessary to get isSubmitted() to work
|
||||||
if (! $this->getSubmitLabel() || $this->isSubmitted()) {
|
if (! $this->getSubmitLabel() || $this->isSubmitted()) {
|
||||||
if ($this->isValid($formData)
|
if ($this->isValid($formData)
|
||||||
|
|
Loading…
Reference in New Issue