From 8cfb23c1ffa56549c582b9e4a0d3d40484be89e8 Mon Sep 17 00:00:00 2001 From: Samuele Masetto Date: Fri, 12 Aug 2022 15:14:11 +0200 Subject: [PATCH] contact tokens in welcome email --- CRM/Mailing/Event/BAO/Confirm.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/CRM/Mailing/Event/BAO/Confirm.php b/CRM/Mailing/Event/BAO/Confirm.php index c6b8f73e68..d69a4f18bc 100644 --- a/CRM/Mailing/Event/BAO/Confirm.php +++ b/CRM/Mailing/Event/BAO/Confirm.php @@ -108,17 +108,22 @@ class CRM_Mailing_Event_BAO_Confirm extends CRM_Mailing_Event_DAO_Confirm { $text = CRM_Utils_String::htmlToText($component->body_html); } - $bao = new CRM_Mailing_BAO_Mailing(); - $bao->body_text = $text; - $bao->body_html = $html; - $tokens = $bao->getTokens(); - - $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']); $html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE); - - $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']); $text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE); + $tokenProcessor = new \Civi\Token\TokenProcessor(\Civi::dispatcher(), [ + 'controller' => __CLASS__, + 'smarty' => FALSE, + ]); + + $tokenProcessor->addMessage('body_html', $html, 'text/html'); + $tokenProcessor->addMessage('body_text', $text, 'text/plain'); + + $tokenProcessor->addRow(['contactId' => $contact_id]); + $tokenProcessor->evaluate(); + $html = $tokenProcessor->getRow(0)->render('body_html'); + $text = $tokenProcessor->getRow(0)->render('body_text'); + $mailParams = [ 'groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, -- 2.25.1