[icinga-checkins] icinga.org: icingaweb2-module-director/master: PropertyModifierSplit: allow null when empty

git at icinga.org git at icinga.org
Thu Jul 21 23:50:39 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Jul 21 23:39:33 2016 +0200

PropertyModifierSplit: allow null when empty

fixes #12060

---

 .../PropertyModifier/PropertyModifierSplit.php     |   21 ++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/library/Director/PropertyModifier/PropertyModifierSplit.php b/library/Director/PropertyModifier/PropertyModifierSplit.php
index e3f78bc..4a6fef6 100644
--- a/library/Director/PropertyModifier/PropertyModifierSplit.php
+++ b/library/Director/PropertyModifier/PropertyModifierSplit.php
@@ -16,10 +16,31 @@ class PropertyModifierSplit extends PropertyModifierHook
                 'One or more characters that should be used to split this string'
             )
         ));
+
+        $form->addElement('select', 'when_empty', array(
+            'label'       => $form->translate('When empty'),
+            'required'    => true,
+            'description' => $form->translate(
+                'What should happen when the given string is empty?'
+            ),
+            'value'        => 'empty_array',
+            'multiOptions' => $form->optionalEnum(array(
+                'empty_array' => $form->translate('return an empty array'),
+                'null'        => $form->translate('return NULL'),
+            ))
+        ));
     }
 
     public function transform($value)
     {
+        if (! strlen(trim($value))) {
+            if ($this->getSetting('when_empty', 'empty_array') === 'empty_array') {
+                return array();
+            } else {
+                return null;
+            }
+        }
+
         return preg_split(
             '/' . preg_quote($this->getSetting('delimiter'), '/') . '/',
             $value,



More information about the icinga-checkins mailing list