DirectorDatafieldForm: Implement the unfinished Hook usage
This commit is contained in:
parent
fb85bcb572
commit
e3f7af057f
|
@ -3,6 +3,7 @@
|
||||||
namespace Icinga\Module\Director\Forms;
|
namespace Icinga\Module\Director\Forms;
|
||||||
|
|
||||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||||
|
use Icinga\Web\Hook;
|
||||||
|
|
||||||
class DirectorDatafieldForm extends DirectorObjectForm
|
class DirectorDatafieldForm extends DirectorObjectForm
|
||||||
{
|
{
|
||||||
|
@ -24,14 +25,34 @@ class DirectorDatafieldForm extends DirectorObjectForm
|
||||||
'description' => $this->translate('A description about the field')
|
'description' => $this->translate('A description about the field')
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->addElement('text', '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,
|
||||||
|
'multiOptions' => $this->enumDataTypes(),
|
||||||
|
'class' => 'autosubmit'
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->addElement('text', 'format', array(
|
$this->addElement('hidden', 'format',
|
||||||
'label' => $this->translate('Format'),
|
array('decorators' => array('ViewHelper'))
|
||||||
'description' => $this->translate('Field format (string, json, expression)')
|
);
|
||||||
));
|
|
||||||
|
if (isset($_POST['datatype'])) {
|
||||||
|
$class = $_POST['datatype'];
|
||||||
|
if ($class && array_key_exists($class, $this->enumDataTypes())) {
|
||||||
|
$this->getElement('format')->setValue($class::getFormat());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function enumDataTypes()
|
||||||
|
{
|
||||||
|
$hooks = Hook::all('Director\\DataType');
|
||||||
|
$enum = array(null => '- please choose -');
|
||||||
|
foreach ($hooks as $hook) {
|
||||||
|
$enum[get_class($hook)] = $hook->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $enum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue