diff --git a/Civi/FormProcessor/Type/MailingGroupType.php b/Civi/FormProcessor/Type/MailingGroupType.php index c52717c6d03039f08706f0750aac166aacdbfa85..7911ed11c5d62485f3cef3a995afbe80955b2f0c 100644 --- a/Civi/FormProcessor/Type/MailingGroupType.php +++ b/Civi/FormProcessor/Type/MailingGroupType.php @@ -32,14 +32,10 @@ class MailingGroupType extends AbstractType implements OptionListInterface { public function validateValue($value, $allValues = []) { $multiple = $this->configuration->get('multiple') ? true : false; - if (\CRM_Utils_Type::validate($value, 'Integer', FALSE) === NULL) { - return FALSE; - } - $groups = $this->getOptions(); if ($multiple && is_array($value)) { foreach ($value as $valueItem) { - if (\CRM_Utils_Type::validate($valueItem, 'String', FALSE) === NULL) { + if (\CRM_Utils_Type::validate($valueItem, 'Integer', FALSE) === NULL) { return FALSE; } if (!isset($groups[$valueItem])) { @@ -47,7 +43,7 @@ class MailingGroupType extends AbstractType implements OptionListInterface { } } } elseif (!is_array($value) && $value) { - if (\CRM_Utils_Type::validate($value, 'String', FALSE) === NULL) { + if (\CRM_Utils_Type::validate($value, 'Integer', FALSE) === NULL) { return FALSE; } @@ -76,7 +72,6 @@ class MailingGroupType extends AbstractType implements OptionListInterface { * @return mixed */ public function normalizeValue($value) { - $groups = $this->getOptions(); $multiple = $this->configuration->get('multiple') ? true : false; // Correct array values when field is not multiple. @@ -87,17 +82,7 @@ class MailingGroupType extends AbstractType implements OptionListInterface { $value = reset($value); } - if ($multiple && is_array($value)) { - $return = array(); - foreach($value as $item) { - $return[] = $groups[$item]; - } - return $return; - } elseif (!is_array($value)) { - return $groups[$value]; - } else { - return null; - } + return $value; } /** @@ -108,19 +93,11 @@ class MailingGroupType extends AbstractType implements OptionListInterface { * @return mixed */ public function denormalizeValue($value) { - $groups = $this->getOptions(); $multiple = $this->configuration->get('multiple') ? true : false; if ($multiple && is_array($value)) { - $return = array(); - foreach($value as $item) { - $return[] = $groups[$item]; - } - return $return; - } elseif (!is_array($value)) { - return $groups[$value]; - } else { - return null; + $value = [$value]; } + return $value; } public function getOptions($params) {