* @return array
*/
public static function renderMessageTemplate(array $mailContent, bool $disableSmarty, $contactID, array $smartyAssigns): array {
- if ($contactID) {
- // @todo resolve contact ID below - see https://github.com/civicrm/civicrm-core/pull/19550
- // for things to resolve first.
- $tokens = self::getTokensToResolve($mailContent);
- $mailContent = self::resolveContactTokens($contactID, $tokens, $mailContent, !$disableSmarty);
- }
CRM_Core_Smarty::singleton()->pushScope($smartyAssigns);
$tokenProcessor = new TokenProcessor(\Civi::dispatcher(), ['smarty' => !$disableSmarty]);
$tokenProcessor->addMessage('html', $mailContent['html'], 'text/html');
$tokenProcessor->addMessage('text', $mailContent['text'], 'text/plain');
$tokenProcessor->addMessage('subject', $mailContent['subject'], 'text/plain');
- $tokenProcessor->addRow([]);
+ $tokenProcessor->addRow($contactID ? ['contactId' => $contactID] : []);
$tokenProcessor->evaluate();
foreach ($tokenProcessor->getRows() as $row) {
$mailContent['html'] = $row->render('html');
$mailContent['subject'] = $row->render('subject');
}
CRM_Core_Smarty::singleton()->popScope();
-
$mailContent['subject'] = trim(preg_replace('/[\r\n]+/', ' ', $mailContent['subject']));
return $mailContent;
}
/**
* Test rendering of smarty tokens.
*
- * @throws \CRM_Core_Exception
*/
public function testRenderMessageTemplateIgnoreSmarty(): void {
$messageContent = CRM_Core_BAO_MessageTemplate::renderMessageTemplate([
foreach (array_keys($tokenData) as $key) {
$tokenString .= "{$key}:{contact.{$key}}\n";
}
- $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), []);
+ $tokenProcessor = new TokenProcessor(Civi::dispatcher(), []);
$tokenProcessor->addMessage('html', $tokenString, 'text/html');
$tokenProcessor->addRow(['contactId' => $tokenData['contact_id']]);
$tokenProcessor->evaluate();
display_name:Mr. Robert Smith II
nick_name:Bob
image_URL:https://example.com
-preferred_communication_method:
+preferred_communication_method:Phone
preferred_language:fr_CA
preferred_mail_format:Both
hash:xyz