Skip to content
Snippets Groups Projects
Commit 7e88248b authored by jaapjansma's avatar jaapjansma
Browse files

Made Mailing Group Type multiple

parent 83b36441
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment