From 251d01cb4c22c12a305237106cc6c104557b6ae5 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 10 Jan 2023 11:45:27 +1300 Subject: [PATCH] Fix Contact import e-notice on preview screen --- CRM/Contact/Import/Form/Preview.php | 36 ++++++------------- templates/CRM/Contact/Import/Form/Preview.tpl | 12 +++---- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/CRM/Contact/Import/Form/Preview.php b/CRM/Contact/Import/Form/Preview.php index c133b99c1c..cfc55e5c03 100644 --- a/CRM/Contact/Import/Form/Preview.php +++ b/CRM/Contact/Import/Form/Preview.php @@ -26,7 +26,7 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview { /** * Build the form object. */ - public function buildQuickForm() { + public function buildQuickForm(): void { $this->addElement('text', 'newGroupName', ts('Name for new group'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title')); $this->addElement('text', 'newGroupDesc', ts('Description of new group')); $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE); @@ -38,11 +38,11 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview { ); } - $groups = CRM_Core_PseudoConstant::nestedGroup();; + $groups = CRM_Core_PseudoConstant::nestedGroup(); if (!empty($groups)) { $this->addElement('select', 'groups', ts('Add imported records to existing group(s)'), $groups, [ - 'multiple' => "multiple", + 'multiple' => 'multiple', 'class' => 'crm-select2', ]); } @@ -70,48 +70,32 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview { * @param array $fields * Posted values of the form. * - * @param $files - * @param self $self - * * @return array|bool * list of errors to be posted back to the form */ - public static function formRule($fields, $files, $self) { + public static function formRule(array $fields) { $errors = []; - $invalidTagName = $invalidGroupName = FALSE; - - if (!empty($fields['newTagName'])) { - if (!CRM_Utils_Rule::objectExists(trim($fields['newTagName']), - ['CRM_Core_DAO_Tag'] - ) - ) { - $errors['newTagName'] = ts('Tag \'%1\' already exists.', - [1 => $fields['newTagName']] - ); - $invalidTagName = TRUE; - } + if (!empty($fields['newTagName']) + && !CRM_Utils_Rule::objectExists(trim($fields['newTagName']), ['CRM_Core_DAO_Tag']) + ) { + $errors['newTagName'] = ts('Tag \'%1\' already exists.', [1 => $fields['newTagName']]); } if (!empty($fields['newGroupName'])) { $title = trim($fields['newGroupName']); $name = CRM_Utils_String::titleToVar($title); $query = 'SELECT COUNT(*) FROM civicrm_group WHERE name LIKE %1 OR title LIKE %2'; - $grpCnt = CRM_Core_DAO::singleValueQuery( + if (CRM_Core_DAO::singleValueQuery( $query, [ 1 => [$name, 'String'], 2 => [$title, 'String'], ] - ); - if ($grpCnt) { - $invalidGroupName = TRUE; + )) { $errors['newGroupName'] = ts('Group \'%1\' already exists.', [1 => $fields['newGroupName']]); } } - $self->assign('invalidTagName', $invalidTagName); - $self->assign('invalidGroupName', $invalidGroupName); - return empty($errors) ? TRUE : $errors; } diff --git a/templates/CRM/Contact/Import/Form/Preview.tpl b/templates/CRM/Contact/Import/Form/Preview.tpl index 47283e4dff..eab53cdd04 100644 --- a/templates/CRM/Contact/Import/Form/Preview.tpl +++ b/templates/CRM/Contact/Import/Form/Preview.tpl @@ -143,13 +143,13 @@ {literal} {/literal} -- 2.25.1