From 511d0374ef4fa9a2afcb83232789611077d66e00 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 5 Apr 2020 16:25:37 -0400 Subject: [PATCH] Cleanup custom field handling... twice --- CRM/Contact/Import/Parser.php | 35 +++++++++++++++-------------------- CRM/Utils/DeprecatedUtils.php | 35 +++++++++++++++-------------------- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/CRM/Contact/Import/Parser.php b/CRM/Contact/Import/Parser.php index 146c1b5d37..249862dc71 100644 --- a/CRM/Contact/Import/Parser.php +++ b/CRM/Contact/Import/Parser.php @@ -1238,29 +1238,24 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { if ($customFieldID && array_key_exists($customFieldID, $customFields)) { $htmlType = $customFields[$customFieldID]['html_type'] ?? NULL; - switch ($htmlType) { - case 'CheckBox': - case 'Multi-Select': - if ($val) { - $mulValues = explode(',', $val); - $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE); - $newValues[$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') { - $newValues[$key][$v2['value']] = 1; - } - else { - $newValues[$key][] = $v2['value']; - } - } + if (CRM_Core_BAO_CustomField::isSerialized($customFields[$customFieldID]) && $val) { + $mulValues = explode(',', $val); + $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE); + $newValues[$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') { + $newValues[$key][$v2['value']] = 1; + } + else { + $newValues[$key][] = $v2['value']; } } } - break; + } } } } diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index 4e5e9ce3f0..ebde5c3754 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -435,29 +435,24 @@ function _civicrm_api3_deprecated_add_formatted_param(&$values, &$params) { $fields['Address'][$key] = NULL; $htmlType = $customFields[$customFieldID]['html_type'] ?? NULL; - switch ($htmlType) { - case 'CheckBox': - case 'Multi-Select': - if ($val) { - $mulValues = explode(',', $val); - $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE); - $newValues[$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') { - $newValues[$key][$v2['value']] = 1; - } - else { - $newValues[$key][] = $v2['value']; - } - } + if (CRM_Core_BAO_CustomField::isSerialized($customFields[$customFieldID]) && $val) { + $mulValues = explode(',', $val); + $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE); + $newValues[$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') { + $newValues[$key][$v2['value']] = 1; + } + else { + $newValues[$key][] = $v2['value']; } } } - break; + } } } } -- 2.25.1