diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 21254b6a8591..355bea62e8e3 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -400,6 +400,7 @@ public function buildQuickForm() { $processor->setFormName($formName); $processor->setMetadata($this->getContactImportMetadata()); $processor->setContactTypeByConstant($this->get('contactType')); + $processor->setContactSubType($this->get('contactSubType')); for ($i = 0; $i < $this->_columnCount; $i++) { $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL); @@ -863,37 +864,15 @@ public function loadSavedMapping($processor, $mappingName, $i, $defaults, $js, $ if ($mappingName[$i] != ts('- do not import -')) { if ($processor->getRelationshipKey($i)) { - $contactType = $processor->getContactType(); - //CRM-5125 - $contactSubType = NULL; - if ($this->get('contactSubType')) { - $contactSubType = $this->get('contactSubType'); - } - - $relations = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $contactType, - FALSE, 'label', TRUE, $contactSubType - ); - - foreach ($relations as $key => $var) { - if ($processor->getValidRelationshipKey($i)) { - $relation = $processor->getValidRelationshipKey($i); - break; - } - } $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$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]"] = [$relation, $contactDetails, $websiteTypeId]; - } - else { - - $defaults["mapper[$i]"] = [$relation, $contactDetails, $locationId, $typeId]; + $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i); + if (!$websiteTypeId) { if (!$locationId) { $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n"; } diff --git a/CRM/Import/ImportProcessor.php b/CRM/Import/ImportProcessor.php index 5640c837a96d..035591c4465c 100644 --- a/CRM/Import/ImportProcessor.php +++ b/CRM/Import/ImportProcessor.php @@ -513,6 +513,12 @@ public function getQuickFormJSForField($column) { * @throws \CiviCRM_API3_Exception */ public function getSavedQuickformDefaultsForColumn($column) { + if ($this->getValidRelationshipKey($column)) { + if ($this->getWebsiteTypeID($column)) { + return [$this->getValidRelationshipKey($column), $this->getFieldName($column), $this->getWebsiteTypeID($column)]; + } + return [$this->getValidRelationshipKey($column), $this->getFieldName($column), $this->getLocationTypeID($column), $this->getPhoneOrIMTypeID($column)]; + } if ($this->getWebsiteTypeID($column)) { return [$this->getFieldName($column), $this->getWebsiteTypeID($column)]; } diff --git a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php index b85ad00dc629..50ebd39fcb30 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php +++ b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php @@ -310,10 +310,14 @@ public function mapFieldDataProvider() { ], [ // Yes, the relationship mapping really does use url whereas non relationship uses website because... legacy - ['name' => 'Url', 'contact_type' => 'Individual', 'column_number' => 0, 'website_type_id', 'relationship_type_id' => 1, 'relationship_direction' => 'a_b'], - "document.forms.MapField['mapper[0][2]'].style.display = 'none'; -document.forms.MapField['mapper[0][3]'].style.display = 'none';\n", - ['mapper[0]' => ['1_a_b', 'url', 0, NULL]], + ['name' => 'Url', 'contact_type' => 'Individual', 'column_number' => 0, 'website_type_id' => 1, 'relationship_type_id' => 1, 'relationship_direction' => 'a_b'], + "document.forms.MapField['mapper[0][3]'].style.display = 'none';\n", + ['mapper[0]' => ['1_a_b', 'url', 1]], + ], + [ + ['name' => 'Phone', 'contact_type' => 'Individual', 'column_number' => 0, 'phone_type_id' => 1, 'relationship_type_id' => 1, 'relationship_direction' => 'b_a'], + '', + ['mapper[0]' => ['1_b_a', 'phone', 'Primary', 1]], ], ]; }