Set field to do-not-import if not configured
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 28 Nov 2023 03:14:48 +0000 (16:14 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 28 Nov 2023 03:20:49 +0000 (16:20 +1300)
CRM/Contact/Import/Form/MapField.php

index 06680d140f9ddb3e707c1e28367df2afd5d01691..583ad04dc08760d715df4ce737281787b8849960 100644 (file)
@@ -275,7 +275,12 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
         $last_key = array_key_last($mapper[$i]);
       }
       elseif ($this->getSubmittedValue('savedMapping') && $processor->getFieldName($i)) {
-        $defaults["mapper[$i]"] = $processor->getSavedQuickformDefaultsForColumn($i);
+        $defaultField = $processor->getSavedQuickformDefaultsForColumn($i);
+        if (!array_key_exists($defaultField[0], $this->_mapperFields)) {
+          $defaultField = ['do_not_import'];
+          CRM_Core_Session::setStatus(ts('Data was configured to be imported to column %1 but it is not available. The field has been set to "%2"', [1 => $columnHeader, 2 => $this->_mapperFields['do_not_import']]));
+        }
+        $defaults["mapper[$i]"] = $defaultField;
         $last_key = array_key_last($defaults["mapper[$i]"]) ?? 0;
       }
       else {