From b6828bc5489a815f58e1d096a503f9626ec40085 Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 20 Jul 2023 13:30:37 -0400 Subject: [PATCH] AdminForm - Automatically redirect back to browse page after form submittion This reads from the `paths` metadata in the DAO to look for a 'browse' path; we need to add 'browse' paths to the rest of our entities. --- CRM/Admin/Form.php | 4 ++++ CRM/Core/Form.php | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CRM/Admin/Form.php b/CRM/Admin/Form.php index 99b82b333d..8cc8e785d8 100644 --- a/CRM/Admin/Form.php +++ b/CRM/Admin/Form.php @@ -69,6 +69,10 @@ class CRM_Admin_Form extends CRM_Core_Form { $this->_BAOName = CRM_Core_DAO_AllCoreTables::getBAOClassName(CRM_Core_DAO_AllCoreTables::getFullName($this->getDefaultEntity())); } $this->retrieveValues(); + // Once form is submitted, user should be redirected back to the "browse" page. + if (isset($this->_BAOName::getEntityPaths()['browse'])) { + $this->pushUrlToUserContext($this->_BAOName::getEntityPaths()['browse']); + } } /** diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index f575309d26..a57ebe8dbf 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -2701,14 +2701,18 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } /** - * Push the current url to the userContext. + * Push path to the userContext (defaults to current url path). * * This is like a save point :-). The next status bounce will * return the browser to this url unless another is added. + * + * @param string $path + * Path string e.g. `civicrm/foo/bar?reset=1`, defaults to current path. */ - protected function pushUrlToUserContext(): void { - CRM_Core_Session::singleton() - ->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1')); + protected function pushUrlToUserContext(string $path = NULL): void { + $url = CRM_Utils_System::url($path ?: CRM_Utils_System::currentPath() . '?reset=1', + '', FALSE, NULL, FALSE); + CRM_Core_Session::singleton()->pushUserContext($url); } /** -- 2.25.1