From 821cf44238eb134a0f0499b31b05abe0acaedcfe Mon Sep 17 00:00:00 2001 From: Mathieu Lu Date: Thu, 10 Aug 2023 10:44:13 -0400 Subject: [PATCH] dev/core#4425 Override currentPath for Standalone --- CRM/Utils/System.php | 12 +----------- CRM/Utils/System/Base.php | 11 +++++++++++ CRM/Utils/System/Standalone.php | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 8d57b5bed9..1e59880ce4 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -39,6 +39,7 @@ * @method static void appendCoreResources(\Civi\Core\Event\GenericHookEvent $e) Callback for hook_civicrm_coreResourceList. * @method static void alterAssetUrl(\Civi\Core\Event\GenericHookEvent $e) Callback for hook_civicrm_getAssetUrl. * @method static bool shouldExitAfterFatal() Should the current execution exit after a fatal error? + * @method static string|null currentPath() Path of the current page e.g. 'civicrm/contact/view' */ class CRM_Utils_System { @@ -433,17 +434,6 @@ class CRM_Utils_System { return "$text"; } - /** - * Path of the current page e.g. 'civicrm/contact/view' - * - * @return string|null - * the current menu path - */ - public static function currentPath() { - $config = CRM_Core_Config::singleton(); - return isset($_GET[$config->userFrameworkURLVar]) ? trim($_GET[$config->userFrameworkURLVar], '/') : NULL; - } - /** * Compose a URL. This is a wrapper for `url()` which is optimized for use in Smarty. * diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index c78f72c0c9..c3986180a1 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -172,6 +172,17 @@ abstract class CRM_Utils_System_Base { return $this->url($path, $query, $absolute, $fragment, $frontend, $forceBackend); } + /** + * Path of the current page e.g. 'civicrm/contact/view' + * + * @return string|null + * the current menu path + */ + public static function currentPath() { + $config = CRM_Core_Config::singleton(); + return isset($_GET[$config->userFrameworkURLVar]) ? trim($_GET[$config->userFrameworkURLVar], '/') : NULL; + } + /** * Authenticate the user against the CMS db. * diff --git a/CRM/Utils/System/Standalone.php b/CRM/Utils/System/Standalone.php index c0070e3681..93359926fd 100644 --- a/CRM/Utils/System/Standalone.php +++ b/CRM/Utils/System/Standalone.php @@ -205,6 +205,20 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base { } } + /** + * Path of the current page e.g. 'civicrm/contact/view' + * + * @return string|null + * the current menu path + */ + public static function currentPath() { + $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); + if ($path[0] == '/') { + $path = substr($path, 1); + } + return $path; + } + /** * @inheritDoc * Authenticate the user against the CMS db. -- 2.25.1