From b49f0996da1d6de1e940ae83a23cdf76a2c0b5c8 Mon Sep 17 00:00:00 2001 From: Herb v/d Dool Date: Wed, 15 Feb 2023 17:18:42 -0500 Subject: [PATCH] dev/core#4127 move standalone profile modification to userSystem --- CRM/UF/Page/Group.php | 26 +------------------------- CRM/Utils/System/Base.php | 17 +++++++++++++++++ CRM/Utils/System/DrupalBase.php | 14 ++++++++++++++ CRM/Utils/System/Joomla.php | 13 +++++++++++++ CRM/Utils/System/WordPress.php | 22 ++++++++++++++++++++++ 5 files changed, 67 insertions(+), 25 deletions(-) diff --git a/CRM/UF/Page/Group.php b/CRM/UF/Page/Group.php index 2cf6c83c50..de929317ef 100644 --- a/CRM/UF/Page/Group.php +++ b/CRM/UF/Page/Group.php @@ -216,31 +216,7 @@ class CRM_UF_Page_Group extends CRM_Core_Page { $template->assign('tplFile', 'CRM/Profile/Form/Edit.tpl'); $profile = trim($template->fetch('CRM/Form/default.tpl')); - // not sure how to circumvent our own navigation system to generate the right form url - $urlReplaceWith = 'civicrm/profile/create&gid=' . $gid . '&reset=1'; - if ($config->userSystem->is_drupal && $config->cleanURL) { - $urlReplaceWith = 'civicrm/profile/create?gid=' . $gid . '&reset=1'; - } - $profile = str_replace('civicrm/admin/uf/group', $urlReplaceWith, $profile); - - // FIXME: (CRM-3587) hack to make standalone profile work - // in wordpress and joomla without administrator login - if ($config->userFramework == 'Joomla') { - $profile = str_replace('/administrator/', '/index.php', $profile); - } - elseif ($config->userFramework == 'WordPress') { - //@todo remove this part when it is OK to deprecate CIVICRM_UF_WP_BASEPAGE-CRM-15933 - if (defined('CIVICRM_UF_WP_BASEPAGE')) { - $wpbase = CIVICRM_UF_WP_BASEPAGE; - } - elseif (!empty($config->wpBasePage)) { - $wpbase = $config->wpBasePage; - } - else { - $wpbase = 'index.php'; - } - $profile = str_replace('/wp-admin/admin.php', '/' . $wpbase . '/', $profile); - } + $profile = $config->userSystem->modifyStandaloneProfile($profile, ['gid' => $gid]); // add header files CRM_Core_Resources::singleton()->addCoreResources('html-header'); diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 0fe6c55f24..72ea4f1331 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -1132,4 +1132,21 @@ abstract class CRM_Utils_System_Base { return $contactParameters; } + /** + * Modify standalone profile + * + * @param string $profile + * @param array $params + * + * @return string + */ + public function modifyStandaloneProfile($profile, $params):string { + // Not sure how to circumvent our own navigation system to generate the + // right form url. + $urlReplaceWith = 'civicrm/profile/create&gid=' . $params['gid'] . '&reset=1'; + $profile = str_replace('civicrm/admin/uf/group', $urlReplaceWith, $profile); + + return $profile; + } + } diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index a59bf97f6e..3574213f7d 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -824,4 +824,18 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { return $contactParameters; } + /** + * @inheritdoc + */ + public function modifyStandaloneProfile($profile, $params):string { + $config = CRM_Core_Config::singleton(); + $urlReplaceWith = 'civicrm/profile/create&gid=' . $params['gid'] . '&reset=1'; + if ($config->cleanURL) { + $urlReplaceWith = 'civicrm/profile/create?gid=' . $params['gid'] . '&reset=1'; + } + $profile = str_replace('civicrm/admin/uf/group', $urlReplaceWith, $profile); + + return $profile; + } + } diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index d91cc5f7f7..0117a19bfd 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -1031,4 +1031,17 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { return $contactParameters; } + /** + * @inheritdoc + */ + public function modifyStandaloneProfile($profile, $params):string { + $urlReplaceWith = 'civicrm/profile/create&gid=' . $params['gid'] . '&reset=1'; + $profile = str_replace('civicrm/admin/uf/group', $urlReplaceWith, $profile); + + // FIXME: (CRM-3587) hack to make standalone profile work + // in Joomla without administrator login. + $profile = str_replace('/administrator/', '/index.php', $profile); + return $profile; + } + } diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 4d20f89495..a384dfa6ea 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -1672,4 +1672,26 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { return $contactParameters; } + /** + * @inheritdoc + */ + public function modifyStandaloneProfile($profile, $params):string { + $urlReplaceWith = 'civicrm/profile/create&gid=' . $params['gid'] . '&reset=1'; + $profile = str_replace('civicrm/admin/uf/group', $urlReplaceWith, $profile); + + //@todo remove this part when it is OK to deprecate CIVICRM_UF_WP_BASEPAGE-CRM-15933 + $config = CRM_Core_Config::singleton(); + if (defined('CIVICRM_UF_WP_BASEPAGE')) { + $wpbase = CIVICRM_UF_WP_BASEPAGE; + } + elseif (!empty($config->wpBasePage)) { + $wpbase = $config->wpBasePage; + } + else { + $wpbase = 'index.php'; + } + $profile = str_replace('/wp-admin/admin.php', '/' . $wpbase . '/', $profile); + return $profile; + } + } -- 2.25.1