From: eileen Date: Sun, 18 Aug 2019 08:08:24 +0000 (+1200) Subject: Pass ProcessorObject into loadSavedMapping & use it to load the formName X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a2ca56ec78cfc59e7846caaaa6b94d816f4d5cca;p=civicrm-core.git Pass ProcessorObject into loadSavedMapping & use it to load the formName After a few more steps we can eliminate most of this function & use the processor but this is jusut a very small change.... --- diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 83c54ff2ba..1bca6472de 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -36,6 +36,7 @@ */ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { + use CRM_Contact_Import_MetadataTrait; /** * An array of all contact fields with @@ -193,10 +194,13 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { /** * Build the form object. + * + * @throws \CiviCRM_API3_Exception */ public function buildQuickForm() { + $savedMappingID = (int) $this->get('savedMapping'); //to save the current mappings - if (!$this->get('savedMapping')) { + if (!$savedMappingID) { $saveDetailsName = ts('Save this field mapping'); $this->applyFilter('saveMappingName', 'trim'); $this->add('text', 'saveMappingName', ts('Name')); @@ -396,12 +400,16 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { $formName = 'document.forms.' . $this->_name; //used to warn for mismatch column count or mismatch mapping CRM_Core_Session::singleton()->setStatus(NULL); + $processor = new CRM_Import_ImportProcessor(); + $processor->setMappingID($savedMappingID); + $processor->setFormName($formName); + $processor->setMetadata($this->getContactImportMetadata()); for ($i = 0; $i < $this->_columnCount; $i++) { $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL); if ($this->get('savedMapping')) { - list($defaults, $js) = $this->loadSavedMapping($mappingName, $i, $mappingRelation, $mappingWebsiteType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $defaults, $formName, $js, $hasColumnNames, $dataPatterns, $columnPatterns); + list($defaults, $js) = $this->loadSavedMapping($processor, $mappingName, $i, $mappingRelation, $mappingWebsiteType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns); } else { $js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n"; @@ -840,6 +848,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { } /** + * @param \CRM_Import_ImportProcessor $processor * @param $mappingName * @param int $i * @param $mappingRelation @@ -848,7 +857,6 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { * @param $mappingPhoneType * @param $mappingImProvider * @param array $defaults - * @param string $formName * @param string $js * @param bool $hasColumnNames * @param array $dataPatterns @@ -856,8 +864,9 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { * * @return array */ - public function loadSavedMapping($mappingName, $i, $mappingRelation, $mappingWebsiteType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $defaults, $formName, $js, $hasColumnNames, $dataPatterns, $columnPatterns) { + public function loadSavedMapping($processor, $mappingName, $i, $mappingRelation, $mappingWebsiteType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns) { $jsSet = FALSE; + $formName = $processor->getFormName(); if (isset($mappingName[$i])) { if ($mappingName[$i] != ts('- do not import -')) { diff --git a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php index 9ca03adfa1..854638ddef 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php +++ b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php @@ -321,14 +321,18 @@ document.forms.MapField['mapper[1][3]'].style.display = 'none';\n", $mappingRelation = CRM_Utils_Array::value(1, $mappingRelation); $mappingWebsiteType = CRM_Utils_Array::value(1, $mappingWebsiteType); $defaults = []; - $formName = 'document.forms.MapField'; + $js = ''; $hasColumnNames = TRUE; // @todo - can use metadata trait once https://github.com/civicrm/civicrm-core/pull/15018 is merged. $dataPatterns = []; $columnPatterns = []; + $processor = new CRM_Import_ImportProcessor(); + $processor->setMappingID($mappingID); + $processor->setFormName('document.forms.MapField'); + $processor->setMetadata($this->getContactImportMetadata()); - $return = $form->loadSavedMapping($mappingName, $columnNumber, $mappingRelation, $mappingWebsiteType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $defaults, $formName, $js, $hasColumnNames, $dataPatterns, $columnPatterns); + $return = $form->loadSavedMapping($processor, $mappingName, $columnNumber, $mappingRelation, $mappingWebsiteType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $defaults, $js, $hasColumnNames, $dataPatterns, $columnPatterns); return ['defaults' => $return[0], 'js' => $return[1]]; }