PropertyModifierSplit: allow null when empty

fixes #12060
This commit is contained in:
Thomas Gelf 2016-07-21 23:39:33 +02:00
parent b93f83eddc
commit 9c9516834c
1 changed files with 21 additions and 0 deletions

View File

@ -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,