From bb19328098374116ce382c2aedd38fd058413dfe Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 13 Sep 2021 18:07:01 +1200 Subject: [PATCH] Add 'mock tokens' to force load of needed values --- CRM/Core/BAO/ActionSchedule.php | 10 +++++++--- Civi/Token/TokenCompatSubscriber.php | 2 +- tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 209097cb6b..2520e5652e 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -615,15 +615,15 @@ FROM civicrm_action_schedule cas $mailParams = [ 'groupName' => 'Scheduled Reminder Sender', 'from' => self::pickFromEmail($schedule), - 'toName' => $tokenRow->context['contact']['display_name'], + 'toName' => $tokenRow->render('toName'), 'toEmail' => $toEmail, 'subject' => $tokenRow->render('subject'), 'entity' => 'action_schedule', 'entity_id' => $schedule->id, ]; - if (!$body_html || $tokenRow->context['contact']['preferred_mail_format'] === 'Text' || - $tokenRow->context['contact']['preferred_mail_format'] === 'Both' + $preferredMailFormat = $tokenRow->render('preferred_mail_format'); + if (!$body_html || $preferredMailFormat === 'Text' || $preferredMailFormat === 'Both' ) { // render the & entities in text mode, so that the links work $mailParams['text'] = str_replace('&', '&', $body_text); @@ -658,6 +658,10 @@ FROM civicrm_action_schedule cas $tp->addMessage('body_html', $schedule->body_html, 'text/html'); $tp->addMessage('sms_body_text', $schedule->sms_body_text, 'text/plain'); $tp->addMessage('subject', $schedule->subject, 'text/plain'); + // These 2 are not 'real' tokens - but it tells the processor to load them. + $tp->addMessage('toName', '{contact.display_name}', 'text/plain'); + $tp->addMessage('preferred_mail_format', '{contact.preferred_mail_format}', 'text/plain'); + return $tp; } diff --git a/Civi/Token/TokenCompatSubscriber.php b/Civi/Token/TokenCompatSubscriber.php index 79eac1f259..f4745ec7cd 100644 --- a/Civi/Token/TokenCompatSubscriber.php +++ b/Civi/Token/TokenCompatSubscriber.php @@ -288,7 +288,7 @@ class TokenCompatSubscriber implements EventSubscriberInterface { ); foreach ($hookTokens as $hookToken) { foreach ($messageTokens[$hookToken] as $tokenName) { - $row->format('text/plain')->tokens($hookToken, $tokenName, $contactArray[$row->context['contactId']][$tokenName] ?? ''); + $row->tokens($hookToken, $tokenName, $contactArray[$row->context['contactId']]["{$hookToken}.{$tokenName}"] ?? ''); } } } diff --git a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php index 0f25e72d6b..5cd2d5c491 100644 --- a/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php +++ b/tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php @@ -384,7 +384,7 @@ emo */ public function hookTokenValues(array &$details): void { foreach ($details as $index => $detail) { - $details[$index]['favourite_emoticon'] = 'emo'; + $details[$index]['important_stuff.favourite_emoticon'] = 'emo'; } } -- 2.25.1