$extends = $customFields[$customFieldID]['extends'] ?? NULL;
$htmlType = $customFields[$customFieldID]['html_type'] ?? NULL;
- switch ($htmlType) {
- case 'Select':
- case 'Radio':
- case 'Autocomplete-Select':
- if ($customFields[$customFieldID]['data_type'] == 'String' || $customFields[$customFieldID]['data_type'] == 'Int') {
- $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
- foreach ($customOption as $customValue) {
- $val = $customValue['value'] ?? NULL;
- $label = $customValue['label'] ?? NULL;
- $label = strtolower($label);
- $value = strtolower(trim($formatted[$key]));
- if (($value == $label) || ($value == strtolower($val))) {
- $params[$key] = $formatted[$key] = $val;
- }
- }
+ $dataType = $customFields[$customFieldID]['data_type'] ?? NULL;
+ $serialized = CRM_Core_BAO_CustomField::isSerialized($customFields[$customFieldID]);
+
+ if (!$serialized && in_array($htmlType, ['Select', 'Radio', 'Autocomplete-Select']) && in_array($dataType, ['String', 'Int'])) {
+ $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
+ foreach ($customOption as $customValue) {
+ $val = $customValue['value'] ?? NULL;
+ $label = strtolower($customValue['label'] ?? '');
+ $value = strtolower(trim($formatted[$key]));
+ if (($value == $label) || ($value == strtolower($val))) {
+ $params[$key] = $formatted[$key] = $val;
}
- break;
-
- case 'CheckBox':
- case 'Multi-Select':
-
- if (!empty($formatted[$key]) && !empty($params[$key])) {
- $mulValues = explode(',', $formatted[$key]);
- $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
- $formatted[$key] = [];
- $params[$key] = [];
- foreach ($mulValues as $v1) {
- foreach ($customOption as $v2) {
- if ((strtolower($v2['label']) == strtolower(trim($v1))) ||
- (strtolower($v2['value']) == strtolower(trim($v1)))
- ) {
- if ($htmlType == 'CheckBox') {
- $params[$key][$v2['value']] = $formatted[$key][$v2['value']] = 1;
- }
- else {
- $params[$key][] = $formatted[$key][] = $v2['value'];
- }
- }
+ }
+ }
+ elseif ($serialized && !empty($formatted[$key]) && !empty($params[$key])) {
+ $mulValues = explode(',', $formatted[$key]);
+ $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
+ $formatted[$key] = [];
+ $params[$key] = [];
+ foreach ($mulValues as $v1) {
+ foreach ($customOption as $v2) {
+ if ((strtolower($v2['label']) == strtolower(trim($v1))) ||
+ (strtolower($v2['value']) == strtolower(trim($v1)))
+ ) {
+ if ($htmlType == 'CheckBox') {
+ $params[$key][$v2['value']] = $formatted[$key][$v2['value']] = 1;
+ }
+ else {
+ $params[$key][] = $formatted[$key][] = $v2['value'];
}
}
}
- break;
+ }
}
}
}