mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 07:44:05 +02:00
DirectorDatafieldForm: more robustness...
...to protect ourselves from foreign failures
This commit is contained in:
parent
03ba27d159
commit
a185177e14
@ -2,8 +2,10 @@
|
||||
|
||||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||
use Icinga\Web\Hook;
|
||||
use Exception;
|
||||
|
||||
class DirectorDatafieldForm extends DirectorObjectForm
|
||||
{
|
||||
@ -33,24 +35,40 @@ class DirectorDatafieldForm extends DirectorObjectForm
|
||||
'rows' => '3',
|
||||
));
|
||||
|
||||
$error = false;
|
||||
try {
|
||||
$types = $this->enumDataTypes();
|
||||
} catch (Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
$types = $this->optionalEnum(array());
|
||||
}
|
||||
|
||||
$this->addElement('select', 'datatype', array(
|
||||
'label' => $this->translate('Data type'),
|
||||
'description' => $this->translate('Field type'),
|
||||
'required' => true,
|
||||
'multiOptions' => $this->enumDataTypes(),
|
||||
'multiOptions' => $types,
|
||||
'class' => 'autosubmit',
|
||||
));
|
||||
if ($error) {
|
||||
$this->getElement('datatype')->addError($error);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if ($class = $this->getSentValue('datatype')) {
|
||||
if ($class && array_key_exists($class, $this->enumDataTypes())) {
|
||||
if ($class && array_key_exists($class, $types)) {
|
||||
$this->addSettings($class);
|
||||
}
|
||||
} elseif ($class = $this->object()->datatype) {
|
||||
$this->addSettings($class);
|
||||
}
|
||||
|
||||
// TODO: next line looks like obsolete duplicate code to me
|
||||
$this->addSettings();
|
||||
} catch (Exception $e) {
|
||||
$this->getElement('datatype')->addError($e->getMessage());
|
||||
}
|
||||
|
||||
foreach ($this->object()->getSettings() as $key => $val) {
|
||||
if ($el = $this->getElement($key)) {
|
||||
$el->setValue($val);
|
||||
@ -61,10 +79,17 @@ class DirectorDatafieldForm extends DirectorObjectForm
|
||||
protected function addSettings($class = null)
|
||||
{
|
||||
if ($class === null) {
|
||||
if ($class = $this->getValue('datatype')) {
|
||||
$class::addSettingsFormFields($this);
|
||||
$class = $this->getValue('datatype');
|
||||
}
|
||||
} else {
|
||||
|
||||
if ($class !== null) {
|
||||
if (! class_exists($class)) {
|
||||
throw new ConfigurationError(
|
||||
'The hooked class "%s" for this data field does no longer exist',
|
||||
$class
|
||||
);
|
||||
}
|
||||
|
||||
$class::addSettingsFormFields($this);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user