From 5a3fead131fbc725dbd26480a0e87fad22455996 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 30 Jul 2015 09:22:55 +0200 Subject: [PATCH] DirectorObjectForm: allow to enforce object type... ...when creating new objects --- .../Director/Web/Form/DirectorObjectForm.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 0956edb8..ef270acf 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -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'); }