Improve element handling in the resource config forms

Signed-off-by: Eric Lippmann <eric.lippmann@icinga.com>
This commit is contained in:
Alexander A. Klimov 2016-12-07 15:40:18 +01:00 committed by Eric Lippmann
parent 3889e870a3
commit b44c932de8
1 changed files with 38 additions and 1 deletions

View File

@ -22,6 +22,13 @@ use Icinga\Web\Notification;
class ResourceConfigForm extends ConfigForm
{
/**
* Bogus password when inspecting password elements
*
* @var string
*/
protected static $dummyPassword = '_web_form_5847ed1b5b8ca';
/**
* If the global config must be updated because a resource has been changed, this is the updated global config
*
@ -215,10 +222,14 @@ class ResourceConfigForm extends ConfigForm
} elseif (! $this->config->hasSection($resource)) {
throw new ConfigurationError($this->translate('Unknown resource provided'));
}
$configValues = $this->config->getSection($resource)->toArray();
$configValues['name'] = $resource;
$this->populate($configValues);
foreach ($this->getElements() as $element) {
if ($element->getType() === 'Zend_Form_Element_Password' && strlen($element->getValue())) {
$element->setValue(static::$dummyPassword);
}
}
}
}
@ -395,6 +406,32 @@ class ResourceConfigForm extends ConfigForm
return $this;
}
/**
* {@inheritdoc}
*/
public function getValues($suppressArrayNotation = false)
{
$values = parent::getValues($suppressArrayNotation);
$resource = $this->request->getQuery('resource');
if ($resource !== null && $this->config->hasSection($resource)) {
$resourceConfig = $this->config->getSection($resource)->toArray();
foreach ($this->getElements() as $element) {
if ($element->getType() === 'Zend_Form_Element_Password') {
$name = $element->getName();
if (isset($values[$name]) && $values[$name] === static::$dummyPassword) {
if (isset($resourceConfig[$name])) {
$values[$name] = $resourceConfig[$name];
} else {
unset($values[$name]);
}
}
}
}
}
return $values;
}
/**
* {@inheritDoc}
*/