From 3c23826507d740d79ea52a6a26fc6cea526b4632 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 2 Sep 2019 10:10:54 +1200 Subject: [PATCH] [REF] Import - generate js on the processor class This moves the js calculation to the processor class for some of the function and simplifies it so that the concatenation is done at the end. Test cover is very solid on this --- CRM/Contact/Import/Form/MapField.php | 11 +---------- CRM/Import/ImportProcessor.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index e78e2ea8f2..58423b71a8 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -917,26 +917,17 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { $mappingHeader = $processor->getFieldName($i); $websiteTypeId = $processor->getWebsiteTypeID($i); $locationId = $processor->getLocationTypeID($i); - $phoneType = $processor->getPhoneTypeID($i); - $imProvider = $processor->getIMProviderID($i); $typeId = $processor->getPhoneOrIMTypeID($i); if ($websiteTypeId) { $defaults["mapper[$i]"] = [$mappingHeader, $websiteTypeId]; } else { - if (!$locationId) { - $js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n"; - } //default for IM/phone without related contact $defaults["mapper[$i]"] = [$mappingHeader ?? '', $locationId, $typeId]; } - if ((!$phoneType) && (!$imProvider)) { - $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n"; - } - - $js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n"; + $js .= $processor->getQuickFormJSForField($i); $jsSet = TRUE; } diff --git a/CRM/Import/ImportProcessor.php b/CRM/Import/ImportProcessor.php index 534226a162..535e641f8b 100644 --- a/CRM/Import/ImportProcessor.php +++ b/CRM/Import/ImportProcessor.php @@ -478,4 +478,30 @@ class CRM_Import_ImportProcessor { return !empty($this->getValidRelationships()[$key]) ? TRUE : FALSE; } + /** + * Get the relevant js for quickform. + * + * @param int $column + * + * @return string + * @throws \CiviCRM_API3_Exception + */ + public function getQuickFormJSForField($column) { + $columnNumbersToHide = []; + + if (!$this->getLocationTypeID($column) && !$this->getWebsiteTypeID($column)) { + $columnNumbersToHide[] = 1; + } + if (!$this->getPhoneOrIMTypeID($column)) { + $columnNumbersToHide[] = 2; + } + $columnNumbersToHide[] = 3; + + $jsClauses = []; + foreach ($columnNumbersToHide as $columnNumber) { + $jsClauses[] = $this->getFormName() . "['mapper[$column][" . $columnNumber . "]'].style.display = 'none';"; + } + return implode("\n", $jsClauses) . "\n"; + } + } -- 2.25.1