[icinga-checkins] icinga.org: icingaweb2-module-director/master: DirectorObjectForm: getSentOrResolvedObjectValue

git at icinga.org git at icinga.org
Sun Feb 28 17:12:40 CET 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sun Feb 28 14:47:23 2016 +0100

DirectorObjectForm: getSentOrResolvedObjectValue

Introduce new helper method and fix former bahaviour

---

 library/Director/Web/Form/DirectorObjectForm.php |   27 +++++++++++++++++-----
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php
index 9654d57..d035569 100644
--- a/library/Director/Web/Form/DirectorObjectForm.php
+++ b/library/Director/Web/Form/DirectorObjectForm.php
@@ -702,22 +702,37 @@ abstract class DirectorObjectForm extends QuickForm
         return $this->getSentValue($name) === $this->getElement($name)->getLabel();
     }
 
-    public function getSentOrObjectValue($name, $default = null)
+    public function getSentOrResolvedObjectValue($name, $default = null)
+    {
+        return $this->getSentOrObjectValue($name, $default, true);
+    }
+
+    public function getSentOrObjectValue($name, $default = null, $resolved = false)
     {
         // TODO: check whether getSentValue is still needed since element->getValue
         //       is in place (currently for form element default values only)
 
         if ($this->hasObject()) {
             $value = $this->getSentValue($name);
-            if ($value === null) {
+            if ($value === null || $value === '') {
 
                 $object = $this->getObject();
 
-                if ($object->hasProperty($name) && $object->$name !== null) {
-                    return $object->$name;
+                if ($object->hasProperty($name)) {
+                    if ($resolved) {
+                        $objectProperty = $object->getResolvedProperty($name);
+                    } else {
+                        $objectProperty = $object->$name;
+                    }
+                } else {
+                    $objectProperty = null;
+                }
+
+                if ($objectProperty !== null) {
+                    return $objectProperty;
                 }
 
-                if (null !== ($val = $this->getElement('object_type')->getValue())) {
+                if (null !== ($val = $this->getElement($name)->getValue())) {
                     return $val;
                 }
 
@@ -732,7 +747,7 @@ abstract class DirectorObjectForm extends QuickForm
                 return $val;
             }
 
-            if (null !== ($val = $this->getElement('object_type')->getValue())) {
+            if (null !== ($val = $this->getElement($name)->getValue())) {
                 return $val;
             }
 



More information about the icinga-checkins mailing list