From 97f0c02af4906d2cf784eb8e343417e9c2ae1a7c Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Thu, 16 Jan 2025 12:13:13 +0000 Subject: [PATCH] Temporary fix for frontend AfformTokens being generated incorrectly --- CRM/Utils/System/WordPress.php | 10 +++++++++- ext/afform/core/Civi/Afform/Tokens.php | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 1e09f2e0b68..fe28f2cbf28 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -339,7 +339,14 @@ public function url( // Overwrite base URL if we already have a front-end URL. if (!$forceBackend && $frontend_url != '') { - $base = $frontend_url; + if (!empty(\Civi::$statics['afformtokenscontext'])) { + \Civi::log()->debug('url(): In afformTokens context. Clearing $frontend_url'); + $frontend_url = ''; + } + else { + // Only if not in afform tokens context + $base = $frontend_url; + } } $queryParts = []; @@ -408,6 +415,7 @@ public function url( } + unset(Civi::$statics['afformtokenscontext']); return $final; } diff --git a/ext/afform/core/Civi/Afform/Tokens.php b/ext/afform/core/Civi/Afform/Tokens.php index 9740cfb6b03..394740e7cf0 100644 --- a/ext/afform/core/Civi/Afform/Tokens.php +++ b/ext/afform/core/Civi/Afform/Tokens.php @@ -100,6 +100,7 @@ public static function evaluateTokens(\Civi\Token\Event\TokenValueEvent $e) { if (empty($row->context['contactId'])) { continue; } + \Civi::$statics['afformtokenscontext'] = TRUE; $url = self::createUrl($afform, $row->context['contactId']); $row->format('text/plain')->tokens(static::$prefix, $afform['name'] . 'Url', $url); $row->format('text/html')->tokens(static::$prefix, $afform['name'] . 'Link', sprintf('%s', htmlentities($url), htmlentities($afform['title'] ?? $afform['name'])));