From 8a7480f5f6b216f88343c20e6e760bbedc7a086c Mon Sep 17 00:00:00 2001 From: Herb v/d Dool Date: Tue, 10 Jan 2023 17:17:17 -0500 Subject: [PATCH] Core#2301 Add Drupal 8+ specific check and extract to CRM_Utils_System_Base --- CRM/Core/BAO/UFGroup.php | 10 +++++----- CRM/Utils/System/Base.php | 9 +++++++++ CRM/Utils/System/Drupal8.php | 14 ++++++++++++++ CRM/Utils/System/DrupalBase.php | 12 ++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 0c9d57caa2..5cbb50cc7e 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -916,11 +916,11 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup implements \Civi\Core\Ho $template = CRM_Core_Smarty::singleton(); - // Hide CRM error messages if they are displayed using drupal form_set_error. - if (!empty($_POST) && CRM_Core_Config::singleton()->userFramework == 'Drupal') { - if (arg(0) == 'user' || (arg(0) == 'admin' && arg(1) == 'people')) { - $template->assign('suppressForm', TRUE); - } + // Hide CRM error messages if they are set based on CMS + // criteria. + if (!empty($_POST)) { + $supressForm = CRM_Core_Config::singleton()->userSystem->suppressProfileFormErrors(); + $template->assign('suppressForm', $supressForm); } $templateFile = "CRM/Profile/Form/{$profileID}/Dynamic.tpl"; diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 9426bf28ad..553cb333bd 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -1114,4 +1114,13 @@ abstract class CRM_Utils_System_Base { return []; } + /** + * Suppress profile form errors + * + * @return bool + */ + public function suppressProfileFormErrors() { + return FALSE; + } + } diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index c26f2b63b0..445b4ebbb4 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -901,4 +901,18 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { return 'Unknown'; } + /** + * @inheritdoc + */ + public function suppressProfileFormErrors() { + // Suppress the errors if they are displayed using + // drupal form_set_error. + $current_path = \Drupal::service('path.current')->getPath(); + $path_args = explode('/', $current_path); + if ($path_args[1] == 'user' || ($path_args[1] == 'admin' && $path_args[2] == 'people')) { + return TRUE; + } + return FALSE; + } + } diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index f5b916bf09..c0e567a4b2 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -721,4 +721,16 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { ]; } + /** + * @inheritdoc + */ + public function suppressProfileFormErrors() { + // Suppress the errors if they are displayed using + // drupal form_set_error. + if (arg(0) == 'user' || (arg(0) == 'admin' && arg(1) == 'people')) { + return TRUE; + } + return FALSE; + } + } -- 2.25.1