From 3ace1ae52f32d0c4ef84ce9e3f71126be5f59196 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 11 Jul 2021 21:25:50 -0700 Subject: [PATCH] (REF) MessageTemplate::sendTemplate() - Divide $params in model, view, and envelope sections --- CRM/Core/BAO/MessageTemplate.php | 37 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/CRM/Core/BAO/MessageTemplate.php b/CRM/Core/BAO/MessageTemplate.php index de3daf5ad3..6d9aced734 100644 --- a/CRM/Core/BAO/MessageTemplate.php +++ b/CRM/Core/BAO/MessageTemplate.php @@ -408,24 +408,34 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { * @throws \API_Exception */ public static function sendTemplate($params) { - $defaults = [ + $modelDefaults = [ // instance of WorkflowMessageInterface, containing a list of data to provide to the message-template 'model' => NULL, - // option value name of the template + // Symbolic name of the workflow step. Matches the option-value-name of the template. 'valueName' => NULL, - // ID of the template - 'messageTemplateID' => NULL, - // content of the message template - // Ex: ['msg_subject' => 'Hello {contact.display_name}', 'msg_html' => '...', 'msg_text' => '...'] - // INTERNAL: 'messageTemplate' is currently only intended for use within civicrm-core only. For downstream usage, future updates will provide comparable public APIs. - 'messageTemplate' => NULL, - // contact id if contact tokens are to be replaced - 'contactId' => NULL, // additional template params (other than the ones already set in the template singleton) 'tplParams' => [], // additional token params (passed to the TokenProcessor) // INTERNAL: 'tokenContext' is currently only intended for use within civicrm-core only. For downstream usage, future updates will provide comparable public APIs. 'tokenContext' => [], + // properties to import directly to the model object + 'modelProps' => NULL, + // contact id if contact tokens are to be replaced; alias for tokenContext.contactId + 'contactId' => NULL, + ]; + $viewDefaults = [ + // ID of the specific template to load + 'messageTemplateID' => NULL, + // content of the message template + // Ex: ['msg_subject' => 'Hello {contact.display_name}', 'msg_html' => '...', 'msg_text' => '...'] + // INTERNAL: 'messageTemplate' is currently only intended for use within civicrm-core only. For downstream usage, future updates will provide comparable public APIs. + 'messageTemplate' => NULL, + // whether this is a test email (and hence should include the test banner) + 'isTest' => FALSE, + // Disable Smarty? + 'disableSmarty' => FALSE, + ]; + $envelopeDefaults = [ // the From: header 'from' => NULL, // the recipient’s name @@ -440,12 +450,8 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { 'replyTo' => NULL, // email attachments 'attachments' => NULL, - // whether this is a test email (and hence should include the test banner) - 'isTest' => FALSE, // filename of optional PDF version to add as attachment (do not include path) 'PDFFilename' => NULL, - // Disable Smarty? - 'disableSmarty' => FALSE, ]; // Allow WorkflowMessage to run any filters/mappings/cleanups. @@ -455,7 +461,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { // Subsequent hooks use $params. Retaining the $params['model'] might be nice - but don't do it unless you figure out how to ensure data-consistency (eg $params['tplParams'] <=> $params['model']). // If you want to expose the model via hook, consider interjecting a new Hook::alterWorkflowMessage($model) between `importAll()` and `exportAll()`. - $params = array_merge($defaults, $params); + $params = array_merge($modelDefaults, $viewDefaults, $envelopeDefaults, $params); CRM_Utils_Hook::alterMailParams($params, 'messageTemplate'); if (!is_int($params['messageTemplateID']) && !is_null($params['messageTemplateID'])) { @@ -499,6 +505,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $config = CRM_Core_Config::singleton(); if (isset($params['isEmailPdf']) && $params['isEmailPdf'] == 1) { + // FIXME: $params['contributionId'] is not modeled in the parameter list. When is it supplied? Should probably move to tokenContext.contributionId. $pdfHtml = CRM_Contribute_BAO_ContributionPage::addInvoicePdfToEmail($params['contributionId'], $params['contactId']); if (empty($params['attachments'])) { $params['attachments'] = []; -- 2.25.1