[REF][Import] [Contact] Clean up preview screen
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 2 May 2022 23:27:56 +0000 (11:27 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 3 May 2022 02:07:46 +0000 (14:07 +1200)
This gets rid of the crazy code on the preview screen - relying on getMappingFieldFromMapperInput
to compile the titles and

CRM/Contact/Import/Form/MapField.php
CRM/Contact/Import/Form/Preview.php
templates/CRM/Contact/Import/Form/MapTable.tpl

index 7e69bb72ae76f6e4fd6969c7a5f6ca84bdc765d5..3f2da38aba9c4f68cfefe55bcb8b5badd4cf1a13 100644 (file)
@@ -521,18 +521,6 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
     }
 
     $this->set('columnNames', $this->_columnNames);
-    $this->set('websites', $parserParameters['mapperWebsiteType']);
-    $this->set('locations', $locations);
-    $this->set('phones', $parserParameters['mapperPhoneType']);
-    $this->set('ims', $parserParameters['mapperImProvider']);
-    $this->set('related', $parserParameters['mapperRelated']);
-    $this->set('relatedContactType', $parserParameters['relatedContactType']);
-    $this->set('relatedContactDetails', $parserParameters['relatedContactDetails']);
-    $this->set('relatedContactLocType', $parserParameters['relatedContactLocType']);
-    $this->set('relatedContactPhoneType', $parserParameters['relatedContactPhoneType']);
-    $this->set('relatedContactImProvider', $parserParameters['relatedContactImProvider']);
-    $this->set('relatedContactWebsiteType', $parserParameters['relatedContactWebsiteType']);
-    $this->set('mapper', $mapper);
 
     // store mapping Id to display it in the preview page
     $this->set('loadMappingId', CRM_Utils_Array::value('mappingId', $params));
index 805bfd1376d2fae374cd515ae26b47b170e02e7f..ba6e91843239497b53f0b27b8184ba55ad2b9f4a 100644 (file)
@@ -76,10 +76,6 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview {
     }
 
     $properties = array(
-      'mapper',
-      'locations',
-      'phones',
-      'ims',
       'columnCount',
       'totalRowCount',
       'validRowCount',
@@ -88,15 +84,10 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview {
       'downloadErrorRecordsUrl',
       'downloadConflictRecordsUrl',
       'downloadMismatchRecordsUrl',
-      'related',
-      'relatedContactDetails',
-      'relatedContactLocType',
-      'relatedContactPhoneType',
-      'relatedContactImProvider',
-      'websites',
-      'relatedContactWebsiteType',
     );
 
+    $this->assign('mapper', $this->getMappedFieldLabels());
+
     foreach ($properties as $property) {
       $this->assign($property, $this->get($property));
     }
@@ -296,4 +287,24 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview {
     $importJob->isComplete();
   }
 
+  /**
+   * Get the mapped fields as an array of labels.
+   *
+   * e.g
+   * ['First Name', 'Employee Of - First Name', 'Home - Street Address']
+   *
+   * @return array
+   * @throws \API_Exception
+   * @throws \CRM_Core_Exception
+   */
+  protected function getMappedFieldLabels(): array {
+    $mapper = [];
+    $parser = new CRM_Contact_Import_Parser_Contact();
+    $parser->setUserJobID($this->getUserJobID());
+    foreach ($this->getSubmittedValue('mapper') as $columnNumber => $mappedField) {
+      $mapper[$columnNumber] = $parser->getMappedFieldLabel($parser->getMappingFieldFromMapperInput($mappedField, 0, $columnNumber));
+    }
+    return $mapper;
+  }
+
 }
index aaa9ed885150d188c9008b91a3dc38db810bbcf5..e0fbce6125fbecffb077c489c57775c4cbf02397 100644 (file)
         {* Display mapper <select> field for 'Map Fields', and mapper value for 'Preview' *}
         <td class="form-item even-row{if $wizard.currentStepName == 'Preview'} labels{/if}">
           {if $wizard.currentStepName == 'Preview'}
-            {if $relatedContactDetails && $relatedContactDetails[$i] != ''}
-                {$mapper[$i]} - {$relatedContactDetails[$i]}
-              {if $relatedContactLocType && $relatedContactLocType[$i] != ''} - {$relatedContactLocType[$i]}{/if}
-              {if $relatedContactPhoneType && $relatedContactPhoneType[$i] != ''} - {$relatedContactPhoneType[$i]}{/if}
-              {* append IM Service Provider type for related contact *}
-              {if  $relatedContactImProvider && $relatedContactImProvider[$i] != ''} - {$relatedContactImProvider[$i]}{/if}
-              {* append website type *}
-              {if  $relatedContactWebsiteType && $relatedContactWebsiteType[$i] != ''} - {$relatedContactWebsiteType[$i]}{/if}
-            {else}
-              {if $locations[$i]}{$locations[$i]} - {/if}
-              {if $phones[$i]}{$phones[$i]} - {/if}
-              {* append IM Service provider type for contact *}
-              {if $ims[$i]}{$ims[$i]} - {/if}
-              {* append website type *}
-              {if $websites[$i]}{$websites[$i]} - {/if}
-              {$mapper[$i]}
-            {/if}
+            {$mapperField}
           {else}
             {$mapperField.html|smarty:nodefaults}
           {/if}