[Import][ref] Minor code improvement - move setDefaults to processor
authoreileen <emcnaughton@wikimedia.org>
Mon, 2 Sep 2019 07:00:08 +0000 (19:00 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 2 Sep 2019 07:02:43 +0000 (19:02 +1200)
CRM/Contact/Import/Form/MapField.php
CRM/Import/ImportProcessor.php

index 58423b71a8a34c3ee66ab6eafe6a897ba38855c7..21254b6a8591ce2ad8e9c272aeb9daeafa30fb03 100644 (file)
@@ -914,19 +914,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
           $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;
index 535e641f8b2abf75aadbf8b95afa18531ae86610..5640c837a96dca89110cfea857139793be87286a 100644 (file)
@@ -504,4 +504,19 @@ class CRM_Import_ImportProcessor {
     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)];
+  }
+
 }