From 68e3bc34581df6cb175e8b5296950d790f4c357a Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 25 Jul 2019 01:11:27 +1200 Subject: [PATCH] Determine front end pages in drupal Alternative to https://github.com/civicrm/civicrm-drupal/pull/546/files that I think narrows the scope since it means we are not changing an existing property --- CRM/Utils/System/Base.php | 13 +++++++++++++ CRM/Utils/System/DrupalBase.php | 22 ++++++++++++++++++++++ Civi/Core/Themes.php | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 2e675243c5..0dca55f657 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -414,6 +414,19 @@ abstract class CRM_Utils_System_Base { return FALSE; } + /** + * Is a front end page being accessed. + * + * Generally this would be a contribution form or other public page as opposed to a backoffice page (like contact edit). + * + * @todo Drupal uses the is_public setting - clarify & rationalise. See https://github.com/civicrm/civicrm-drupal/pull/546/files + * + * @return bool + */ + public function isFrontEndPage() { + return CRM_Core_Config::singleton()->userFrameworkFrontend; + } + /** * Get user login URL for hosting CMS (method declared in each CMS system class) * diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 75d04ca712..829b3870d1 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -663,4 +663,26 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { return (!empty($language->language)) ? $language->language : $language; } + /** + * Is a front end page being accessed. + * + * Generally this would be a contribution form or other public page as opposed to a backoffice page (like contact edit). + * + * See https://github.com/civicrm/civicrm-drupal/pull/546/files + * + * @return bool + */ + public function isFrontEndPage() { + // Get the menu items. + $args = explode('?', $_GET['q']); + $path = $args[0]; + + // Get the menu for above URL. + $item = CRM_Core_Menu::get($path); + if (!empty(CRM_Utils_Array::value('is_public', $item))) { + return TRUE; + } + return FALSE; + } + } diff --git a/Civi/Core/Themes.php b/Civi/Core/Themes.php index 0413fde1a9..16968eb7a3 100644 --- a/Civi/Core/Themes.php +++ b/Civi/Core/Themes.php @@ -85,7 +85,7 @@ class Themes { if ($this->activeThemeKey === NULL) { // Ambivalent: is it better to use $config->userFrameworkFrontend or $template->get('urlIsPublic')? $config = \CRM_Core_Config::singleton(); - $settingKey = $config->userFrameworkFrontend ? 'theme_frontend' : 'theme_backend'; + $settingKey = $config->userSystem->isFrontEndPage() ? 'theme_frontend' : 'theme_backend'; $themeKey = Civi::settings()->get($settingKey); if ($themeKey === 'default') { -- 2.25.1