DirectorDatafieldForm: Implement the unfinished Hook usage

This commit is contained in:
Alexander Fuhr 2015-07-24 15:29:27 +02:00
parent fb85bcb572
commit e3f7af057f
1 changed files with 28 additions and 7 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use Icinga\Web\Hook;
class DirectorDatafieldForm extends DirectorObjectForm
{
@ -24,14 +25,34 @@ class DirectorDatafieldForm extends DirectorObjectForm
'description' => $this->translate('A description about the field')
));
$this->addElement('text', 'datatype', array(
'label' => $this->translate('Data type'),
'description' => $this->translate('Field type')
$this->addElement('select', 'datatype', array(
'label' => $this->translate('Data type'),
'description' => $this->translate('Field type'),
'required' => true,
'multiOptions' => $this->enumDataTypes(),
'class' => 'autosubmit'
));
$this->addElement('text', 'format', array(
'label' => $this->translate('Format'),
'description' => $this->translate('Field format (string, json, expression)')
));
$this->addElement('hidden', 'format',
array('decorators' => array('ViewHelper'))
);
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;
}
}