From a9f13f01b933b204681010390feae08658901ed3 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 5 Sep 2019 12:12:38 +1200 Subject: [PATCH] Move calculation of js for import fields WITH relationship keys to processor. As should be obvious we can collapse a lot more out with the next commit now.... --- CRM/Contact/Import/Form/MapField.php | 26 +------------------------- CRM/Import/ImportProcessor.php | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 355bea62e8..0b445d8457 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -864,32 +864,8 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { if ($mappingName[$i] != ts('- do not import -')) { if ($processor->getRelationshipKey($i)) { - - $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$i])); - $websiteTypeId = $processor->getWebsiteTypeID($i); - $locationId = $processor->getLocationTypeID($i); - $phoneType = $processor->getPhoneTypeID($i); - $imProvider = $processor->getIMProviderID($i); - $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i); - if (!$websiteTypeId) { - if (!$locationId) { - $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n"; - } - } - // fix for edge cases, CRM-4954 - if ($contactDetails == 'image_url') { - $contactDetails = str_replace('url', 'URL', $contactDetails); - } - - if (!$contactDetails) { - $js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n"; - } - - if ((!$phoneType) && (!$imProvider)) { - $js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n"; - } - //$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n"; + $js = $processor->getQuickFormJSForField($i); $jsSet = TRUE; } else { diff --git a/CRM/Import/ImportProcessor.php b/CRM/Import/ImportProcessor.php index 035591c446..453fe317f5 100644 --- a/CRM/Import/ImportProcessor.php +++ b/CRM/Import/ImportProcessor.php @@ -488,20 +488,32 @@ class CRM_Import_ImportProcessor { */ public function getQuickFormJSForField($column) { $columnNumbersToHide = []; - - if (!$this->getLocationTypeID($column) && !$this->getWebsiteTypeID($column)) { - $columnNumbersToHide[] = 1; + if ($this->getRelationshipKey($column)) { + if (!$this->getWebsiteTypeID($column) && !$this->getLocationTypeID($column)) { + $columnNumbersToHide[] = 2; + } + if (!$this->getFieldName($column)) { + $columnNumbersToHide[] = 1; + } + if (!$this->getPhoneOrIMTypeID($column)) { + $columnNumbersToHide[] = 3; + } } - if (!$this->getPhoneOrIMTypeID($column)) { - $columnNumbersToHide[] = 2; + else { + if (!$this->getLocationTypeID($column) && !$this->getWebsiteTypeID($column)) { + $columnNumbersToHide[] = 1; + } + if (!$this->getPhoneOrIMTypeID($column)) { + $columnNumbersToHide[] = 2; + } + $columnNumbersToHide[] = 3; } - $columnNumbersToHide[] = 3; $jsClauses = []; foreach ($columnNumbersToHide as $columnNumber) { $jsClauses[] = $this->getFormName() . "['mapper[$column][" . $columnNumber . "]'].style.display = 'none';"; } - return implode("\n", $jsClauses) . "\n"; + return empty($jsClauses) ? '' : implode("\n", $jsClauses) . "\n"; } /** -- 2.25.1