Skip to content

Commit

Permalink
MessageTemplate - Restore filtering of $params
Browse files Browse the repository at this point in the history
The prior commit had the effect of dropping any filtering that happend on `$params`.
  • Loading branch information
totten committed Sep 28, 2021
1 parent fd0e4bd commit bd010d5
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions CRM/Core/BAO/MessageTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ public static function revert($id) {
* @see sendTemplate()
*/
public static function renderTemplate($params) {
[$mailContent, $params] = self::renderTemplateRaw($params);
return CRM_Utils_Array::subset($mailContent, ['subject', 'text', 'html']);
}

/**
* Render a message template.
*
* @param array $params
* Mixed render parameters. See sendTemplate() for more details.
* @return array
* Tuple of [$mailContent, $updatedParams].
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @see sendTemplate()
*/
protected static function renderTemplateRaw($params) {
$modelDefaults = [
// instance of WorkflowMessageInterface, containing a list of data to provide to the message-template
'model' => NULL,
Expand Down Expand Up @@ -329,7 +345,8 @@ public static function renderTemplate($params) {
$rendered['subject'] = trim(preg_replace('/[\r\n]+/', ' ', $rendered['subject']));
}
$nullSet = ['subject' => NULL, 'text' => NULL, 'html' => NULL];
return array_merge($nullSet, $mailContent, $rendered);
$mailContent = array_merge($nullSet, $mailContent, $rendered);
return [$mailContent, $params];
}

/**
Expand All @@ -344,7 +361,13 @@ public static function renderTemplate($params) {
* @throws \API_Exception
*/
public static function sendTemplate($params) {
$params = array_merge($params, self::renderTemplate($params));
[$mailContent, $params] = self::renderTemplateRaw($params);

// create the params array
$params['subject'] = $mailContent['subject'];
$params['text'] = $mailContent['text'];
$params['html'] = $mailContent['html'];

// send the template, honouring the target user’s preferences (if any)
$sent = FALSE;
if (!empty($params['toEmail'])) {
Expand All @@ -370,7 +393,7 @@ public static function sendTemplate($params) {
if (empty($params['attachments'])) {
$params['attachments'] = [];
}
$params['attachments'][] = CRM_Utils_Mail::appendPDF('Invoice.pdf', $pdfHtml, $params['format']);
$params['attachments'][] = CRM_Utils_Mail::appendPDF('Invoice.pdf', $pdfHtml, $mailContent['format']);
}
$pdf_filename = '';
if ($config->doNotAttachPDFReceipt &&
Expand All @@ -394,7 +417,7 @@ public static function sendTemplate($params) {
}
}

return [$sent, $params['subject'], $params['text'], $params['html']];
return [$sent, $mailContent['subject'], $mailContent['text'], $mailContent['html']];
}

/**
Expand Down

0 comments on commit bd010d5

Please sign in to comment.