From 14bf68060eff4488473fc7ece4a33364b1211fcc Mon Sep 17 00:00:00 2001 From: Alice Frumin Date: Mon, 18 Jul 2016 17:04:04 -0400 Subject: [PATCH] CRM-19099 mailing: send mailing content array to hook --- CRM/Core/BAO/MessageTemplate.php | 60 ++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/CRM/Core/BAO/MessageTemplate.php b/CRM/Core/BAO/MessageTemplate.php index c5bc66220d..a46dfbddfc 100644 --- a/CRM/Core/BAO/MessageTemplate.php +++ b/CRM/Core/BAO/MessageTemplate.php @@ -339,7 +339,9 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { 'PDFFilename' => NULL, ); $params = array_merge($defaults, $params); + CRM_Utils_Hook::alterMailParams($params); + if ((!$params['groupName'] || !$params['valueName'] ) && @@ -379,12 +381,16 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { } } - $subject = $dao->subject; - $text = $dao->text; - $html = $dao->html; - $format = $dao->format; + $mailContent = array( + 'subject' => $dao->subject, + 'text' => $dao->text, + 'html' => $dao->html, + 'format' => $dao->format, + ); $dao->free(); - CRM_Utils_Hook::alterMailContent($dao); + + CRM_Utils_Hook::alterMailContent($mailContent); + // add the test banner (if requested) if ($params['isTest']) { $query = "SELECT msg_subject subject, msg_text text, msg_html html @@ -395,9 +401,9 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $testDao = CRM_Core_DAO::executeQuery($query); $testDao->fetch(); - $subject = $testDao->subject . $subject; - $text = $testDao->text . $text; - $html = preg_replace('/html}", $html); + $mailContent['subject'] = $testDao->subject . $mailContent['subject']; + $mailContent['text'] = $testDao->text . $mailContent['text']; + $mailContent['html'] = preg_replace('/html}", $mailContent['html']); $testDao->free(); } @@ -405,9 +411,9 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $domain = CRM_Core_BAO_Domain::getDomain(); $hookTokens = array(); $mailing = new CRM_Mailing_BAO_Mailing(); - $mailing->subject = $subject; - $mailing->body_text = $text; - $mailing->body_html = $html; + $mailing->subject = $mailingContent['subject']; + $mailing->body_text = $mailContent['text']; + $mailing->body_html = $mailContent['html']; $tokens = $mailing->getTokens(); CRM_Utils_Hook::tokens($hookTokens); $categories = array_keys($hookTokens); @@ -450,14 +456,14 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $contact = $contact[$contactID]; } - $subject = CRM_Utils_Token::replaceDomainTokens($subject, $domain, FALSE, $tokens['text'], TRUE); - $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text'], TRUE); - $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html'], TRUE); + $mailingContent['subject'] = CRM_Utils_Token::replaceDomainTokens($mailingContent['subject'], $domain, FALSE, $tokens['text'], TRUE); + $mailContent['text'] = CRM_Utils_Token::replaceDomainTokens($mailContent['text'], $domain, FALSE, $tokens['text'], TRUE); + $mailContent['html'] = CRM_Utils_Token::replaceDomainTokens($mailContent['html'], $domain, TRUE, $tokens['html'], TRUE); if ($contactID) { - $subject = CRM_Utils_Token::replaceContactTokens($subject, $contact, FALSE, $tokens['text'], FALSE, TRUE); - $text = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $tokens['text'], FALSE, TRUE); - $html = CRM_Utils_Token::replaceContactTokens($html, $contact, FALSE, $tokens['html'], FALSE, TRUE); + $mailingContent['subject'] = CRM_Utils_Token::replaceContactTokens($mailingContent['subject'], $contact, FALSE, $tokens['text'], FALSE, TRUE); + $mailContent['text'] = CRM_Utils_Token::replaceContactTokens($mailContent['text'], $contact, FALSE, $tokens['text'], FALSE, TRUE); + $mailContent['html'] = CRM_Utils_Token::replaceContactTokens($mailContent['html'], $contact, FALSE, $tokens['html'], FALSE, TRUE); $contactArray = array($contactID => $contact); CRM_Utils_Hook::tokenValues($contactArray, @@ -469,13 +475,13 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { ); $contact = $contactArray[$contactID]; - $subject = CRM_Utils_Token::replaceHookTokens($subject, $contact, $categories, TRUE); - $text = CRM_Utils_Token::replaceHookTokens($text, $contact, $categories, TRUE); - $html = CRM_Utils_Token::replaceHookTokens($html, $contact, $categories, TRUE); + $mailingContent['subject'] = CRM_Utils_Token::replaceHookTokens($mailingContent['subject'], $contact, $categories, TRUE); + $mailContent['text'] = CRM_Utils_Token::replaceHookTokens($mailContent['text'], $contact, $categories, TRUE); + $mailContent['html'] = CRM_Utils_Token::replaceHookTokens($mailContent['html'], $contact, $categories, TRUE); } // strip whitespace from ends and turn into a single line - $subject = "{strip}$subject{/strip}"; + $mailingContent['subject'] = "{strip}{$mailingContent['subject']}{/strip}"; // parse the three elements with Smarty $smarty = CRM_Core_Smarty::singleton(); @@ -494,9 +500,9 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $sent = FALSE; // create the params array - $params['subject'] = $subject; - $params['text'] = $text; - $params['html'] = $html; + $params['subject'] = $mailingContent['subject']; + $params['text'] = $mailContent['text']; + $params['html'] = $mailContent['html']; if ($params['toEmail']) { $contactParams = array(array('email', 'LIKE', $params['toEmail'], 0, 1)); @@ -518,7 +524,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { if (empty($params['attachments'])) { $params['attachments'] = array(); } - $params['attachments'][] = CRM_Utils_Mail::appendPDF('Invoice.pdf', $pdfHtml, $format); + $params['attachments'][] = CRM_Utils_Mail::appendPDF('Invoice.pdf', $pdfHtml, $mailContent['format']); } $pdf_filename = ''; if ($config->doNotAttachPDFReceipt && @@ -528,7 +534,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { if (empty($params['attachments'])) { $params['attachments'] = array(); } - $params['attachments'][] = CRM_Utils_Mail::appendPDF($params['PDFFilename'], $params['html'], $format); + $params['attachments'][] = CRM_Utils_Mail::appendPDF($params['PDFFilename'], $params['html'], $mailContent['format']); if (isset($params['tplParams']['email_comment'])) { $params['html'] = $params['tplParams']['email_comment']; $params['text'] = strip_tags($params['tplParams']['email_comment']); @@ -542,7 +548,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { } } - return array($sent, $subject, $text, $html); + return array($sent, $mailingContent['subject'], $mailContent['text'], $mailContent['html']); } } -- 2.25.1