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;
|
namespace Icinga\Module\Director\Forms;
|
||||||
|
|
||||||
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||||
use Icinga\Web\Hook;
|
use Icinga\Web\Hook;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class DirectorDatafieldForm extends DirectorObjectForm
|
class DirectorDatafieldForm extends DirectorObjectForm
|
||||||
{
|
{
|
||||||
@ -33,24 +35,40 @@ class DirectorDatafieldForm extends DirectorObjectForm
|
|||||||
'rows' => '3',
|
'rows' => '3',
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$error = false;
|
||||||
|
try {
|
||||||
|
$types = $this->enumDataTypes();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$error = $e->getMessage();
|
||||||
|
$types = $this->optionalEnum(array());
|
||||||
|
}
|
||||||
|
|
||||||
$this->addElement('select', 'datatype', array(
|
$this->addElement('select', 'datatype', array(
|
||||||
'label' => $this->translate('Data type'),
|
'label' => $this->translate('Data type'),
|
||||||
'description' => $this->translate('Field type'),
|
'description' => $this->translate('Field type'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'multiOptions' => $this->enumDataTypes(),
|
'multiOptions' => $types,
|
||||||
'class' => 'autosubmit',
|
'class' => 'autosubmit',
|
||||||
));
|
));
|
||||||
|
if ($error) {
|
||||||
|
$this->getElement('datatype')->addError($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
if ($class = $this->getSentValue('datatype')) {
|
if ($class = $this->getSentValue('datatype')) {
|
||||||
if ($class && array_key_exists($class, $this->enumDataTypes())) {
|
if ($class && array_key_exists($class, $types)) {
|
||||||
$this->addSettings($class);
|
$this->addSettings($class);
|
||||||
}
|
}
|
||||||
} elseif ($class = $this->object()->datatype) {
|
} elseif ($class = $this->object()->datatype) {
|
||||||
$this->addSettings($class);
|
$this->addSettings($class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: next line looks like obsolete duplicate code to me
|
||||||
$this->addSettings();
|
$this->addSettings();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->getElement('datatype')->addError($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($this->object()->getSettings() as $key => $val) {
|
foreach ($this->object()->getSettings() as $key => $val) {
|
||||||
if ($el = $this->getElement($key)) {
|
if ($el = $this->getElement($key)) {
|
||||||
$el->setValue($val);
|
$el->setValue($val);
|
||||||
@ -61,10 +79,17 @@ class DirectorDatafieldForm extends DirectorObjectForm
|
|||||||
protected function addSettings($class = null)
|
protected function addSettings($class = null)
|
||||||
{
|
{
|
||||||
if ($class === null) {
|
if ($class === null) {
|
||||||
if ($class = $this->getValue('datatype')) {
|
$class = $this->getValue('datatype');
|
||||||
$class::addSettingsFormFields($this);
|
|
||||||
}
|
}
|
||||||
} 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);
|
$class::addSettingsFormFields($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user