From 8224bb1ad6c4d6124a716e49292e8af20674067e Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 24 Aug 2023 00:48:10 -0700 Subject: [PATCH] (dev/core#4531) Afform Mail Tokens - Fix rendering for localized/individual email While sending the localized email, some UF's may reboot the container mid-execution. This change ensures that the listeners will be re-registered. It also makes the code prettier. --- ext/afform/core/Civi/Afform/Tokens.php | 17 ++++++++++++++++- ext/afform/core/afform.php | 7 ------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ext/afform/core/Civi/Afform/Tokens.php b/ext/afform/core/Civi/Afform/Tokens.php index 7d291791e4b9..aa50defa49f2 100644 --- a/ext/afform/core/Civi/Afform/Tokens.php +++ b/ext/afform/core/Civi/Afform/Tokens.php @@ -12,8 +12,10 @@ namespace Civi\Afform; use Civi\Core\Event\GenericHookEvent; +use Civi\Core\Service\AutoService; use Civi\Crypto\Exception\CryptoException; use CRM_Afform_ExtensionUtil as E; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Every afform with the property `is_token=true` should have a corresponding @@ -21,8 +23,21 @@ * * @see MockPublicFormTest * @package Civi\Afform + * @service civi.afform.tokens */ -class Tokens { +class Tokens extends AutoService implements EventSubscriberInterface { + + public static function getSubscribedEvents(): array { + if (!\CRM_Extension_System::singleton()->getMapper()->isActiveModule('authx')) { + return []; + } + + return [ + 'hook_civicrm_alterMailContent' => 'applyCkeditorWorkaround', + 'hook_civicrm_tokens' => 'hook_civicrm_tokens', + 'hook_civicrm_tokenValues' => 'hook_civicrm_tokenValues', + ]; + } /** * CKEditor makes it hard to set an `href` to a token, so we often get diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 97dc6143c60f..ca1f7acdfa10 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -58,13 +58,6 @@ function afform_civicrm_config(&$config) { $dispatcher->addListener('hook_civicrm_alterAngular', ['\Civi\Afform\AfformMetadataInjector', 'preprocess']); $dispatcher->addListener('hook_civicrm_check', ['\Civi\Afform\StatusChecks', 'hook_civicrm_check']); $dispatcher->addListener('civi.afform.get', ['\Civi\Api4\Action\Afform\Get', 'getCustomGroupBlocks']); - - // Register support for email tokens - if (CRM_Extension_System::singleton()->getMapper()->isActiveModule('authx')) { - $dispatcher->addListener('hook_civicrm_alterMailContent', ['\Civi\Afform\Tokens', 'applyCkeditorWorkaround']); - $dispatcher->addListener('hook_civicrm_tokens', ['\Civi\Afform\Tokens', 'hook_civicrm_tokens']); - $dispatcher->addListener('hook_civicrm_tokenValues', ['\Civi\Afform\Tokens', 'hook_civicrm_tokenValues']); - } } /**