[icinga-checkins] icinga.org: icingaweb2-module-director/master: DirectorObjectForm: get rid of object_type magic

git at icinga.org git at icinga.org
Thu Feb 18 00:52:39 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: 7b1c17799d8d3d7d4306776851fdb686bc8e47cd
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=7b1c17799d8d3d7d4306776851fdb686bc8e47cd

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed Feb 17 21:50:06 2016 +0100

DirectorObjectForm: get rid of object_type magic

---

 library/Director/Web/Form/DirectorObjectForm.php |   24 ++++++++++------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php
index d485b5a..1c28baf 100644
--- a/library/Director/Web/Form/DirectorObjectForm.php
+++ b/library/Director/Web/Form/DirectorObjectForm.php
@@ -18,8 +18,6 @@ abstract class DirectorObjectForm extends QuickForm
 
     protected $deleteButtonName;
 
-    protected $objectType = 'object';
-
     protected $fieldsDisplayGroup;
 
     protected $displayGroups = array();
@@ -46,7 +44,7 @@ abstract class DirectorObjectForm extends QuickForm
 
     protected function isTemplate()
     {
-        return $this->objectType === 'template';
+        return $this->getSentOrObjectValue('object_type') === 'template';
     }
 
     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()
     {
         if ($this->object === null || ! $this->object->hasBeenLoadedFromDb()) {
@@ -629,9 +621,6 @@ abstract class DirectorObjectForm extends QuickForm
         }
 
         if ($object instanceof IcingaObject) {
-            if (! $object->hasBeenLoadedFromDb() && $object->hasProperty('object_type')) {
-                $object->object_type = $this->objectType;
-            }
             $this->handleImports($object, $values);
             $this->handleProperties($object, $values);
             $this->handleCustomVars($object, $post);
@@ -721,6 +710,10 @@ abstract class DirectorObjectForm extends QuickForm
                     return $object->$name;
                 }
 
+                if (null !== ($val = $this->getElement('object_type')->getValue())) {
+                    return $val;
+                }
+
                 return $default;
             } else {
 
@@ -732,6 +725,10 @@ abstract class DirectorObjectForm extends QuickForm
                 return $val;
             }
 
+            if (null !== ($val = $this->getElement('object_type')->getValue())) {
+                return $val;
+            }
+
             return $default;
         }
     }
@@ -788,7 +785,8 @@ abstract class DirectorObjectForm extends QuickForm
         if ($this->object()->supportsImports()) {
             $templates = $this->enumAllowedTemplates();
 
-            if (empty($templates)) {
+            // TODO: getObjectname is a confusing method name
+            if (empty($templates) && $this->getObjectname() !== 'Command') {
                 $default = 'template';
                 $types = array('template' => $this->translate('Template'));
             } else {



More information about the icinga-checkins mailing list