Add 'mock tokens' to force load of needed values
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 13 Sep 2021 06:07:01 +0000 (18:07 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 14 Sep 2021 05:12:07 +0000 (17:12 +1200)
CRM/Core/BAO/ActionSchedule.php
Civi/Token/TokenCompatSubscriber.php
tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php

index 209097cb6b097943604e56ed4ba3c20d9c590896..2520e5652ea27a3c944ba9b179b8ef8cda13d122 100644 (file)
@@ -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 &amp; entities in text mode, so that the links work
       $mailParams['text'] = str_replace('&amp;', '&', $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;
   }
 
index 79eac1f25955a9cfa71ad3a8d292cf2823c1e6d3..f4745ec7cd0f6dfb39a05b0f9d1f514a96b87cb7 100644 (file)
@@ -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}"] ?? '');
         }
       }
     }
index 0f25e72d6b4f00a24254c06c5d05362e346a049d..5cd2d5c4917df65f1b4760c9cad38bf4f4e07cb7 100644 (file)
@@ -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';
     }
   }