DirectorObjectForm: get rid of object_type magic

This commit is contained in:
Thomas Gelf 2016-02-17 21:50:06 +01:00
parent 1d24efd103
commit 7b1c17799d
1 changed files with 11 additions and 13 deletions
library/Director/Web/Form

View File

@ -18,8 +18,6 @@ abstract class DirectorObjectForm extends QuickForm
protected $deleteButtonName; protected $deleteButtonName;
protected $objectType = 'object';
protected $fieldsDisplayGroup; protected $fieldsDisplayGroup;
protected $displayGroups = array(); protected $displayGroups = array();
@ -46,7 +44,7 @@ abstract class DirectorObjectForm extends QuickForm
protected function isTemplate() protected function isTemplate()
{ {
return $this->objectType === 'template'; return $this->getSentOrObjectValue('object_type') === 'template';
} }
protected function handleImports($object, & $values) protected function handleImports($object, & $values)
@ -381,12 +379,6 @@ abstract class DirectorObjectForm extends QuickForm
} }
} }
public function setObjectType($type)
{
$this->objectType = $type;
return $this;
}
protected function setButtons() protected function setButtons()
{ {
if ($this->object === null || ! $this->object->hasBeenLoadedFromDb()) { if ($this->object === null || ! $this->object->hasBeenLoadedFromDb()) {
@ -629,9 +621,6 @@ abstract class DirectorObjectForm extends QuickForm
} }
if ($object instanceof IcingaObject) { if ($object instanceof IcingaObject) {
if (! $object->hasBeenLoadedFromDb() && $object->hasProperty('object_type')) {
$object->object_type = $this->objectType;
}
$this->handleImports($object, $values); $this->handleImports($object, $values);
$this->handleProperties($object, $values); $this->handleProperties($object, $values);
$this->handleCustomVars($object, $post); $this->handleCustomVars($object, $post);
@ -721,6 +710,10 @@ abstract class DirectorObjectForm extends QuickForm
return $object->$name; return $object->$name;
} }
if (null !== ($val = $this->getElement('object_type')->getValue())) {
return $val;
}
return $default; return $default;
} else { } else {
@ -732,6 +725,10 @@ abstract class DirectorObjectForm extends QuickForm
return $val; return $val;
} }
if (null !== ($val = $this->getElement('object_type')->getValue())) {
return $val;
}
return $default; return $default;
} }
} }
@ -788,7 +785,8 @@ abstract class DirectorObjectForm extends QuickForm
if ($this->object()->supportsImports()) { if ($this->object()->supportsImports()) {
$templates = $this->enumAllowedTemplates(); $templates = $this->enumAllowedTemplates();
if (empty($templates)) { // TODO: getObjectname is a confusing method name
if (empty($templates) && $this->getObjectname() !== 'Command') {
$default = 'template'; $default = 'template';
$types = array('template' => $this->translate('Template')); $types = array('template' => $this->translate('Template'));
} else { } else {