From 9c9516834ca3db87bd7ebbde9243d9c05cc64237 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 21 Jul 2016 23:39:33 +0200 Subject: [PATCH] PropertyModifierSplit: allow null when empty fixes #12060 --- .../PropertyModifierSplit.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/library/Director/PropertyModifier/PropertyModifierSplit.php b/library/Director/PropertyModifier/PropertyModifierSplit.php index e3f78bc3..4a6fef6b 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,