$contactFieldsBelowWeightMessage = self::validateRequiredContactMatchFields('Individual', $importKeys);
foreach ($requiredFields as $field => $title) {
- if (!in_array($field, $importKeys)) {
+ if (!in_array($field, $importKeys, TRUE)) {
if ($field === 'target_contact_id') {
- if (!$contactFieldsBelowWeightMessage || in_array('external_identifier', $importKeys)) {
+ if (!$contactFieldsBelowWeightMessage || in_array('external_identifier', $importKeys, TRUE)) {
continue;
}
$fieldMessage .= ts('Missing required contact matching fields.')
* @throws \CRM_Core_Exception
*/
public function buildQuickForm(): void {
- $savedMappingID = (int) $this->getSubmittedValue('savedMapping');
- $this->buildSavedMappingFields($savedMappingID);
+ $this->addSavedMappingFields();
$this->addFormRule(['CRM_Activity_Import_Form_MapField', 'formRule']);
//-------- end of saved mapping stuff ---------
* @param array $fields
* Posted values of the form.
*
- * @return array
+ * @return array|bool
* list of errors to be posted back to the form
*/
- public static function formRule($fields) {
+ public static function formRule(array $fields) {
$errors = [];
- // define so we avoid notices below
- $errors['_qf_default'] = '';
if (!array_key_exists('savedMapping', $fields)) {
$importKeys = [];
$errors['_qf_default'] = $missingFields;
}
}
-
- 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 Activity'))) {
- $errors['saveMappingName'] = ts('Duplicate Import Mapping Name');
- }
- }
- }
-
- if (empty($errors['_qf_default'])) {
- unset($errors['_qf_default']);
- }
- if (!empty($errors)) {
- if (!empty($errors['saveMappingName'])) {
- $_flag = 1;
- $assignError = new CRM_Core_Page();
- $assignError->assign('mappingDetailsError', $_flag);
- }
- return $errors;
- }
-
- return TRUE;
+ return $errors ?: TRUE;
}
/**
* @param array $fields
* Posted values of the form.
*
- * @return array|true
+ * @return array|bool
* list of errors to be posted back to the form
*/
- public static function formRule($fields) {
- $errors = [];
+ public static function formRule(array $fields) {
if (!empty($fields['saveMapping'])) {
- $nameField = $fields['saveMappingName'] ?? NULL;
- if (empty($nameField)) {
- $errors['saveMappingName'] = ts('Name is required to save Import Mapping');
- }
- else {
- $mappingTypeId = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Mapping', 'mapping_type_id', 'Import Contact');
- if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) {
- $errors['saveMappingName'] = ts('Duplicate Import Mapping Name');
- }
- }
- }
- $template = CRM_Core_Smarty::singleton();
- if (!empty($fields['saveMapping'])) {
- $template->assign('isCheked', TRUE);
+ CRM_Core_Smarty::singleton()->assign('isCheked', TRUE);
}
- return empty($errors) ? TRUE : $errors;
+ return parent::mappingRule($fields);
}
/**
*
* @param int|null $savedMappingID
*
+ * @deprecated - working to remove this in favour of `addSavedMappingFields`
* @throws \CiviCRM_API3_Exception
*/
protected function buildSavedMappingFields($savedMappingID) {
//Updating Mapping Records
if ($this->getSubmittedValue('updateMapping')) {
foreach (array_keys($this->getColumnHeaders()) as $i) {
- $this->saveMappingField($this->getSubmittedValue('mappingId'), $i, TRUE);
+ $this->saveMappingField((int) $this->getSubmittedValue('mappingId'), $i, TRUE);
}
+ $this->updateUserJobMetadata('mapping', ['id' => (int) $this->getSubmittedValue('mappingId')]);
}
//Saving Mapping Details and Records
if ($this->getSubmittedValue('saveMapping')) {
$this->saveMappingField($savedMappingID, $i, FALSE);
}
$this->set('savedMapping', $savedMappingID);
+ $this->updateUserJobMetadata('mapping', ['id' => $savedMappingID]);
}
}
return [$sel, $headerPatterns];
}
+ /**
+ * Add the saved mapping fields to the form.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ protected function addSavedMappingFields(): void {
+ $savedMappingID = (int) $this->getSubmittedValue('savedMapping');
+ $this->buildSavedMappingFields($savedMappingID);
+ $this->addFormRule(['CRM_Import_Form_MapField', 'mappingRule']);
+ }
+
+ /**
+ * Global validation rules for the form.
+ *
+ * @param array $fields
+ * Posted values of the form.
+ *
+ * @return array|true
+ * list of errors to be posted back to the form
+ */
+ public static function mappingRule($fields) {
+ $errors = [];
+ if (!empty($fields['saveMapping'])) {
+ $nameField = $fields['saveMappingName'] ?? NULL;
+ if (empty($nameField)) {
+ $errors['saveMappingName'] = ts('Name is required to save Import Mapping');
+ }
+ else {
+ $mappingTypeId = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Mapping', 'mapping_type_id', 'Import Contact');
+ if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) {
+ $errors['saveMappingName'] = ts('Duplicate Import Mapping Name');
+ }
+ }
+ }
+ // This is horrible & should be removed once gone from tpl
+ if (!empty($errors['saveMappingName'])) {
+ $_flag = 1;
+ $assignError = new CRM_Core_Page();
+ $assignError->assign('mappingDetailsError', $_flag);
+ }
+ return empty($errors) ? TRUE : $errors;
+ }
+
}