Skip to content

Commit

Permalink
Merge pull request #16968 from colemanw/multi-cleanup
Browse files Browse the repository at this point in the history
[REF] CustomField code cleanup
  • Loading branch information
colemanw authored Apr 7, 2020
2 parents a486eec + e30142b commit 669974b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
6 changes: 1 addition & 5 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,7 @@ public function buildQuickForm() {
// Recursively set defaults for nested fields
if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' || $name == 'honor')) {
foreach ($contact[$name] as $fieldName => $fieldValue) {
if (is_array($fieldValue) && !in_array($this->_fields[$name][$fieldName]['html_type'], [
'Multi-Select',
'AdvMulti-Select',
])
) {
if (is_array($fieldValue) && $this->_fields[$name][$fieldName]['html_type'] == 'CheckBox') {
foreach ($fieldValue as $key => $value) {
$defaults["{$name}[{$fieldName}][{$key}]"] = $value;
}
Expand Down
25 changes: 12 additions & 13 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1316,10 +1316,10 @@ public static function setDefaults(&$groupTree, &$defaults, $viewMode = FALSE, $
}

$elementName = $field['element_name'];
$serialize = CRM_Core_BAO_CustomField::isSerialized($field);

switch ($field['html_type']) {
case 'Multi-Select':
case 'CheckBox':
if ($serialize) {
if ($field['data_type'] != 'Country' && $field['data_type'] != 'StateProvince') {
$defaults[$elementName] = [];
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($field['id'], $inactiveNeeded);
if ($viewMode) {
Expand Down Expand Up @@ -1377,10 +1377,8 @@ public static function setDefaults(&$groupTree, &$defaults, $viewMode = FALSE, $
}
}
}
break;

case 'Multi-Select Country':
case 'Multi-Select State/Province':
}
else {
if (isset($value)) {
$checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
foreach ($checkedValue as $val) {
Expand All @@ -1389,19 +1387,19 @@ public static function setDefaults(&$groupTree, &$defaults, $viewMode = FALSE, $
}
}
}
break;

case 'Select Country':
}
}
else {
if ($field['data_type'] == 'Country') {
if ($value) {
$defaults[$elementName] = $value;
}
else {
$config = CRM_Core_Config::singleton();
$defaults[$elementName] = $config->defaultContactCountry;
}
break;

default:
}
else {
if ($field['data_type'] == "Float") {
$defaults[$elementName] = (float) $value;
}
Expand All @@ -1413,6 +1411,7 @@ public static function setDefaults(&$groupTree, &$defaults, $viewMode = FALSE, $
else {
$defaults[$elementName] = $value;
}
}
}
}
}
Expand Down

0 comments on commit 669974b

Please sign in to comment.