now Automated Messages call alterMailContent hook
authorSamuele Masetto <samuele.masetto@gmail.com>
Wed, 31 Aug 2022 15:24:11 +0000 (17:24 +0200)
committerSamuele Masetto <samuele.masetto@gmail.com>
Wed, 31 Aug 2022 15:24:11 +0000 (17:24 +0200)
CRM/Mailing/Event/BAO/Confirm.php
CRM/Mailing/Event/BAO/Resubscribe.php
CRM/Mailing/Event/BAO/Subscribe.php
CRM/Mailing/Event/BAO/Unsubscribe.php

index 044941e23e2475b483723d411c74abdba5a53b9b..79a61fe090b12e1d0d6924e7744aed66df6850cf 100644 (file)
@@ -107,8 +107,13 @@ class CRM_Mailing_Event_BAO_Confirm extends CRM_Mailing_Event_DAO_Confirm {
       $text = CRM_Utils_String::htmlToText($component->body_html);
     }
 
-    $html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE);
-    $text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE);
+    $bao = new CRM_Mailing_BAO_Mailing();
+    $bao->body_text = $text;
+    $bao->body_html = $html;
+    $templates = $bao->getTemplates();
+
+    $html = CRM_Utils_Token::replaceWelcomeTokens($templates['html'], $group->title, TRUE);
+    $text = CRM_Utils_Token::replaceWelcomeTokens($templates['text'], $group->title, FALSE);
 
     $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [
       'controller' => __CLASS__,
index 4a4db396350c0b43fda00e0d821fff61fa8b93ac..4ad33c8479509e97b3368632652ffedc0021b197 100644 (file)
@@ -234,13 +234,15 @@ class CRM_Mailing_Event_BAO_Resubscribe {
     $bao->body_text = $text;
     $bao->body_html = $html;
     $tokens = $bao->getTokens();
+    $templates = $bao->getTemplates();
+
     if ($eq->format == 'HTML' || $eq->format == 'Both') {
-      $html = CRM_Utils_Token::replaceResubscribeTokens($html, $domain, $groups, TRUE, $eq->contact_id, $eq->hash);
+      $html = CRM_Utils_Token::replaceResubscribeTokens($templates['html'], $domain, $groups, TRUE, $eq->contact_id, $eq->hash);
       $html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, TRUE, $tokens['html']);
       $html = CRM_Utils_Token::replaceMailingTokens($html, $dao, NULL, $tokens['html']);
     }
     if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
-      $text = CRM_Utils_Token::replaceResubscribeTokens($text, $domain, $groups, FALSE, $eq->contact_id, $eq->hash);
+      $text = CRM_Utils_Token::replaceResubscribeTokens($templates['text'], $domain, $groups, FALSE, $eq->contact_id, $eq->hash);
       $text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, FALSE, $tokens['text']);
       $text = CRM_Utils_Token::replaceMailingTokens($text, $dao, NULL, $tokens['text']);
     }
index 3275d40e39093f2d1cacf7269da8dfd16a84b156..5c9044b2bc298da373f13c6d346be60bd26a3626 100644 (file)
@@ -222,8 +222,13 @@ SELECT     civicrm_email.id as email_id
       $text = CRM_Utils_String::htmlToText($component->body_html);
     }
 
-    $html = CRM_Utils_Token::replaceSubscribeTokens($html, $group->title, $url, TRUE);
-    $text = CRM_Utils_Token::replaceSubscribeTokens($text, $group->title, $url, FALSE);
+    $bao = new CRM_Mailing_BAO_Mailing();
+    $bao->body_text = $text;
+    $bao->body_html = $html;
+    $templates = $bao->getTemplates();
+
+    $html = CRM_Utils_Token::replaceSubscribeTokens($templates['html'], $group->title, $url, TRUE);
+    $text = CRM_Utils_Token::replaceSubscribeTokens($templates['text'], $group->title, $url, FALSE);
 
     // render the &amp; entities in text mode, so that the links work
     $text = str_replace('&amp;', '&', $text);
index 17eaf7a3d25526af525e343b17787a265c188c98..f2c92079e923afc9c8a5bbe65c07e05f6c240dc9 100644 (file)
@@ -401,13 +401,15 @@ WHERE  email = %2
     $bao->body_text = $text;
     $bao->body_html = $html;
     $tokens = $bao->getTokens();
+    $templates = $bao->getTemplates();
+
     if ($eq->format == 'HTML' || $eq->format == 'Both') {
-      $html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, TRUE, $eq->contact_id, $eq->hash);
+      $html = CRM_Utils_Token::replaceUnsubscribeTokens($templates['html'], $domain, $groups, TRUE, $eq->contact_id, $eq->hash);
       $html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, TRUE, $tokens['html']);
       $html = CRM_Utils_Token::replaceMailingTokens($html, $dao, NULL, $tokens['html']);
     }
     if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
-      $text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, FALSE, $eq->contact_id, $eq->hash);
+      $text = CRM_Utils_Token::replaceUnsubscribeTokens($templates['text'], $domain, $groups, FALSE, $eq->contact_id, $eq->hash);
       $text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, FALSE, $tokens['text']);
       $text = CRM_Utils_Token::replaceMailingTokens($text, $dao, NULL, $tokens['text']);
     }