From 85352553d77413dd0067c065cf71ce236893c1aa Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 26 Aug 2022 16:35:28 +1200 Subject: [PATCH] Use shared parent formRule in custom import api --- CRM/Custom/Import/Form/MapField.php | 41 ++++------------------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/CRM/Custom/Import/Form/MapField.php b/CRM/Custom/Import/Form/MapField.php index aa1391cb03..7a7b8726c6 100644 --- a/CRM/Custom/Import/Form/MapField.php +++ b/CRM/Custom/Import/Form/MapField.php @@ -8,11 +8,10 @@ class CRM_Custom_Import_Form_MapField extends CRM_Import_Form_MapField { /** * Build the form object. * - * @return void + * @throws \CRM_Core_Exception */ - public function buildQuickForm() { - $savedMappingID = (int) $this->getSubmittedValue('savedMapping'); - $this->buildSavedMappingFields($savedMappingID); + public function buildQuickForm(): void { + $this->addSavedMappingFields(); $this->addFormRule(['CRM_Custom_Import_Form_MapField', 'formRule']); $this->addMapper(); $this->addFormButtons(); @@ -27,7 +26,7 @@ class CRM_Custom_Import_Form_MapField extends CRM_Import_Form_MapField { * @return array|bool * list of errors to be posted back to the form */ - public static function formRule($fields) { + public static function formRule(array $fields) { // todo - this could be shared with other mapFields forms. $errors = []; if (!array_key_exists('savedMapping', $fields)) { @@ -44,37 +43,7 @@ class CRM_Custom_Import_Form_MapField extends CRM_Import_Form_MapField { $errors['_qf_default'] .= ts('Missing required field: %1', [1 => ts('Contact ID or External Identifier')]); } } - - if (!empty($fields['saveMapping'])) { - $nameField = $fields['saveMappingName'] ?? NULL; - if (empty($nameField)) { - $errors['saveMappingName'] = ts('Name is required to save Import Mapping'); - } - else { - if (CRM_Core_BAO_Mapping::checkMapping($nameField, CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Mapping', 'mapping_type_id', 'Import Multi value custom data'))) { - $errors['saveMappingName'] = ts('Duplicate Mapping Name'); - } - } - } - - //display Error if loaded mapping is not selected - if (array_key_exists('loadMapping', $fields)) { - $getMapName = $fields['savedMapping'] ?? NULL; - if (empty($getMapName)) { - $errors['savedMapping'] = ts('Select saved mapping'); - } - } - - if (!empty($errors)) { - if (!empty($errors['saveMappingName'])) { - $_flag = 1; - $assignError = new CRM_Core_Page(); - $assignError->assign('mappingDetailsError', $_flag); - } - return $errors; - } - - return TRUE; + return empty($errors) ? TRUE : $errors; } /** -- 2.25.1