DirectorObjectForm: allow to enforce object type...

...when creating new objects
This commit is contained in:
Thomas Gelf 2015-07-30 09:22:55 +02:00
parent 24cd649908
commit 5a3fead131
1 changed files with 22 additions and 1 deletions

View File

@ -14,6 +14,8 @@ abstract class DirectorObjectForm extends QuickForm
private $className;
private $objectType = 'object';
protected function object($values = array())
{
if ($this->object === null) {
@ -64,6 +66,11 @@ abstract class DirectorObjectForm extends QuickForm
}
}
protected function isTemplate()
{
return $this->objectType === 'template';
}
protected function handleIcingaObject(& $values)
{
$object = $this->object();
@ -129,6 +136,12 @@ abstract class DirectorObjectForm extends QuickForm
}
}
public function setObjectType($type)
{
$this->objectType = $type;
return $this;
}
protected function setElementValue($name, $value = null, $inherited = null)
{
$el = $this->getElement($name);
@ -164,8 +177,12 @@ abstract class DirectorObjectForm extends QuickForm
$values = $this->getValues();
if ($object instanceof IcingaObject) {
$this->handleIcingaObject($values);
if (! array_key_exists('object_type', $values)) {
$object->object_type = $this->objectType;
}
}
$object->setProperties($values);
$msg = sprintf(
$object->hasBeenLoadedFromDb()
? 'The Icinga %s has successfully been stored'
@ -228,7 +245,11 @@ abstract class DirectorObjectForm extends QuickForm
{
$this->prepareElements();
$class = $this->getObjectClassname();
$this->object = $class::load($id, $this->db);
$object = $this->object = $class::load($id, $this->db);
if ($object instanceof IcingaObject) {
$this->objectType = $object->object_type;
}
if (! is_array($id)) {
$this->addHidden('id');
}