From 0a1898e9a78882a29ce7d4b9a5fa60bc0609252c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 16 Dec 2015 20:25:40 +0100 Subject: [PATCH] take into account the different type of choices in empty value --- CustomFields/CustomFieldChoice.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index 8b0d0f647..a34968db3 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -177,7 +177,35 @@ class CustomFieldChoice extends AbstractCustomField public function isEmptyValue($value, CustomField $customField) { - return $value['_choices'] === NULL; + if ($value === NULL) { + return true; + } + + // if only one choice... + if (is_string($value)) { + return empty($value); + } + + // if multiple choice OR multiple/single choice with other + if (is_array($value)) + { + // if allow other + if (isset($value['_choices'])) { + if ($value['_choices'] === NULL) { + return true; + } + if (is_string($value['_choices'])) { + return empty($value); + } + if (is_array($value['_choices'])){ + return count($value['_choices']) > 0; + } + } else { // we do not have 'allow other' + return count($value) > .0; + } + } + + throw \LogicException("This case is not expected."); } /**