public function onSuccess()
 {
     $fieldId = $this->getValue('datafield_id');
     if (!ctype_digit($fieldId)) {
         $field = DirectorDatafield::create(array('varname' => trim($fieldId, '$'), 'caption' => $this->getValue('caption'), 'datatype' => 'Icinga\\Module\\Director\\DataType\\DataTypeString'));
         $field->store($this->getDb());
         $this->setElementValue('datafield_id', $field->id);
         $this->object()->datafield_id = $field->id;
     }
     return parent::onSuccess();
 }
 protected function addCommandField($field, $value = null, $inherited = null, $inheritedFrom = null)
 {
     $datafield = DirectorDatafield::load($field->datafield_id, $this->getDb());
     $name = 'var_' . $datafield->varname;
     $className = $datafield->datatype;
     if (!class_exists($className)) {
         $this->addElement('text', $name, array('disabled' => 'disabled'));
         $el = $this->getElement($name);
         $el->addError(sprintf('Form element could not be created, %s is missing', $className));
         return $el;
     }
     $datatype = new $className();
     $datatype->setSettings($datafield->getSettings());
     $el = $datatype->getFormElement($name, $this);
     $el->setLabel($datafield->caption);
     $el->setDescription($datafield->description);
     if ($field->is_required === 'y' && !$this->isTemplate() && $inherited === null) {
         $el->setRequired(true);
     }
     $this->addElement($el);
     $this->setElementValue($name, $value, $inherited, $inheritedFrom);
     $this->addToCommandFieldsDisplayGroup($el);
     return $el;
 }