From df90a4ddd4196eb7b2e60873500b6cc824808e0b Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 2 Sep 2019 19:00:08 +1200 Subject: [PATCH] [Import][ref] Minor code improvement - move setDefaults to processor --- CRM/Contact/Import/Form/MapField.php | 14 +------------- CRM/Import/ImportProcessor.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 58423b71a8a3..21254b6a8591 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -914,19 +914,7 @@ public function loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $ $jsSet = TRUE; } else { - $mappingHeader = $processor->getFieldName($i); - $websiteTypeId = $processor->getWebsiteTypeID($i); - $locationId = $processor->getLocationTypeID($i); - $typeId = $processor->getPhoneOrIMTypeID($i); - - if ($websiteTypeId) { - $defaults["mapper[$i]"] = [$mappingHeader, $websiteTypeId]; - } - else { - //default for IM/phone without related contact - $defaults["mapper[$i]"] = [$mappingHeader ?? '', $locationId, $typeId]; - } - + $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i); $js .= $processor->getQuickFormJSForField($i); $jsSet = TRUE; diff --git a/CRM/Import/ImportProcessor.php b/CRM/Import/ImportProcessor.php index 535e641f8b2a..5640c837a96d 100644 --- a/CRM/Import/ImportProcessor.php +++ b/CRM/Import/ImportProcessor.php @@ -504,4 +504,19 @@ public function getQuickFormJSForField($column) { return implode("\n", $jsClauses) . "\n"; } + /** + * Get the defaults for the column from the saved mapping. + * + * @param int $column + * + * @return array + * @throws \CiviCRM_API3_Exception + */ + public function getSavedQuickformDefaultsForColumn($column) { + if ($this->getWebsiteTypeID($column)) { + return [$this->getFieldName($column), $this->getWebsiteTypeID($column)]; + } + return [(string) $this->getFieldName($column), $this->getLocationTypeID($column), $this->getPhoneOrIMTypeID($column)]; + } + }