From: Tim Otten Date: Sun, 11 Jul 2021 23:16:01 +0000 (-0700) Subject: MessageTemplate::sendTemplate() - Accept `array $tokenContext` option X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0238a01ebedf0db69643c0adbd4d29589c4cffe4;p=civicrm-core.git MessageTemplate::sendTemplate() - Accept `array $tokenContext` option When using `sendTemplate()`, what values are exported to the TokenProcessor? This option allows you pass options directly through to tokenContext. --- diff --git a/CRM/Core/BAO/MessageTemplate.php b/CRM/Core/BAO/MessageTemplate.php index 2bd753b70d..ec6e83627e 100644 --- a/CRM/Core/BAO/MessageTemplate.php +++ b/CRM/Core/BAO/MessageTemplate.php @@ -385,6 +385,8 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { 'contactId' => NULL, // additional template params (other than the ones already set in the template singleton) 'tplParams' => [], + // additional token params (passed to the TokenProcessor) + 'tokenContext' => [], // the From: header 'from' => NULL, // the recipient’s name @@ -425,7 +427,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $mailContent['subject'] = $params['subject']; } - $mailContent = self::renderMessageTemplate($mailContent, (bool) $params['disableSmarty'], $params['contactId'] ?? NULL, $params['tplParams']); + $mailContent = self::renderMessageTemplate($mailContent, (bool) $params['disableSmarty'], $params['contactId'] ?? NULL, $params['tplParams'], $params['tokenContext']); // send the template, honouring the target user’s preferences (if any) $sent = FALSE; @@ -577,12 +579,15 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { * @param bool $disableSmarty * @param int|NULL $contactID * @param array $smartyAssigns + * Data to pass through to Smarty. + * @param array $tokenContext + * Data to pass through to TokenProcessor. * * @return array */ - public static function renderMessageTemplate(array $mailContent, bool $disableSmarty, $contactID, array $smartyAssigns): array { - $tokenContext = ['smarty' => !$disableSmarty]; - if ($contactID) { + public static function renderMessageTemplate(array $mailContent, bool $disableSmarty, $contactID, array $smartyAssigns, array $tokenContext = []): array { + $tokenContext['smarty'] = !$disableSmarty; + if ($contactID && !isset($tokenContext['contactId'])) { $tokenContext['contactId'] = $contactID; } $result = CRM_Core_TokenSmarty::render(CRM_Utils_Array::subset($mailContent, ['text', 'html', 'subject']), $tokenContext, $smartyAssigns);