From ad05d047cd84e6897412f3da52eca1972c4e7435 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 12 Aug 2019 14:09:28 +1200 Subject: [PATCH] [REF] [Import] extract saved mapping code to parent class I will follow up with narrower adds --- CRM/Contribute/Import/Form/MapField.php | 29 ++++------------------ CRM/Import/Form/MapField.php | 33 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/CRM/Contribute/Import/Form/MapField.php b/CRM/Contribute/Import/Form/MapField.php index 7828bb5216..8d66074834 100644 --- a/CRM/Contribute/Import/Form/MapField.php +++ b/CRM/Contribute/Import/Form/MapField.php @@ -156,31 +156,12 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { /** * Build the form object. + * + * @throws \CiviCRM_API3_Exception */ public function buildQuickForm() { - //to save the current mappings - if (!$this->get('savedMapping')) { - $saveDetailsName = ts('Save this field mapping'); - $this->applyFilter('saveMappingName', 'trim'); - $this->add('text', 'saveMappingName', ts('Name')); - $this->add('text', 'saveMappingDesc', ts('Description')); - } - else { - $savedMapping = $this->get('savedMapping'); - - $mappingName = (string) civicrm_api3('Mapping', 'getvalue', ['id' => $savedMapping, 'return' => 'name']); - $this->set('loadedMapping', $savedMapping); - $this->assign('loadedMapping', $mappingName); - $this->assign('savedName', $mappingName); - $this->add('hidden', 'mappingId', $savedMapping); - - $this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL); - $saveDetailsName = ts('Save as a new field mapping'); - $this->add('text', 'saveMappingName', ts('Name')); - $this->add('text', 'saveMappingDesc', ts('Description')); - } - - $this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, ['onclick' => "showSaveDetails(this)"]); + $savedMappingID = $this->get('savedMapping'); + $this->buildSavedMappingFields($savedMappingID); $this->addFormRule([ 'CRM_Contribute_Import_Form_MapField', @@ -227,7 +208,7 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL); $jsSet = FALSE; if ($this->get('savedMapping')) { - list($mappingName, $mappingContactType) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping); + list($mappingName, $mappingContactType) = CRM_Core_BAO_Mapping::getMappingFields($savedMappingID); $mappingName = $mappingName[1]; $mappingContactType = $mappingContactType[1]; diff --git a/CRM/Import/Form/MapField.php b/CRM/Import/Form/MapField.php index 654f273268..9a5a309a23 100644 --- a/CRM/Import/Form/MapField.php +++ b/CRM/Import/Form/MapField.php @@ -153,4 +153,37 @@ abstract class CRM_Import_Form_MapField extends CRM_Core_Form { return $best; } + /** + * Add the saved mapping fields to the form. + * + * @param int|null $savedMappingID + * + * @throws \CiviCRM_API3_Exception + */ + protected function buildSavedMappingFields($savedMappingID) { + //to save the current mappings + if (!$savedMappingID) { + $saveDetailsName = ts('Save this field mapping'); + $this->applyFilter('saveMappingName', 'trim'); + $this->add('text', 'saveMappingName', ts('Name')); + $this->add('text', 'saveMappingDesc', ts('Description')); + } + else { + $savedMapping = $this->get('savedMapping'); + + $mappingName = (string) civicrm_api3('Mapping', 'getvalue', ['id' => $savedMappingID, 'return' => 'name']); + $this->set('loadedMapping', $savedMapping); + $this->assign('loadedMapping', $mappingName); + $this->assign('savedName', $mappingName); + $this->add('hidden', 'mappingId', $savedMappingID); + + $this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL); + $saveDetailsName = ts('Save as a new field mapping'); + $this->add('text', 'saveMappingName', ts('Name')); + $this->add('text', 'saveMappingDesc', ts('Description')); + } + + $this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, ['onclick' => "showSaveDetails(this)"]); + } + } -- 2.25.1