'PDFFilename' => NULL,
];
+ // Some params have been deprecated/renamed. Synchronize old<=>new params. We periodically resync after exchanging data with other parties.
+ $sync = function () use (&$params, $modelDefaults, $viewDefaults) {
+ CRM_Utils_Array::pathSync($params, ['workflow'], ['valueName']);
+ CRM_Utils_Array::pathSync($params, ['tokenContext', 'contactId'], ['contactId']);
+ CRM_Utils_Array::pathSync($params, ['tokenContext', 'smarty'], ['disableSmarty'], function ($v, bool $isCanon) {
+ return !$v;
+ });
+
+ // Core#644 - handle Email ID passed as "From".
+ if (isset($params['from'])) {
+ $params['from'] = \CRM_Utils_Mail::formatFromAddress($params['from']);
+ }
+ };
+ $sync();
+
// Allow WorkflowMessage to run any filters/mappings/cleanups.
- $model = $params['model'] ?? WorkflowMessage::create($params['valueName'] ?? 'UNKNOWN');
+ $model = $params['model'] ?? WorkflowMessage::create($params['workflow'] ?? 'UNKNOWN');
$params = WorkflowMessage::exportAll(WorkflowMessage::importAll($model, $params));
unset($params['model']);
// 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()`.
+ $sync();
$params = array_merge($modelDefaults, $viewDefaults, $envelopeDefaults, $params);
CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');
$mailContent = self::loadTemplate((string) $params['valueName'], $params['isTest'], $params['messageTemplateID'] ?? NULL, $params['groupName'] ?? '', $params['messageTemplate'], $params['subject'] ?? NULL);
- $params['tokenContext'] = array_merge([
- 'smarty' => (bool) !$params['disableSmarty'],
- 'contactId' => $params['contactId'],
- ], $params['tokenContext']);
+ $sync();
$rendered = CRM_Core_TokenSmarty::render(CRM_Utils_Array::subset($mailContent, ['text', 'html', 'subject']), $params['tokenContext'], $params['tplParams']);
if (isset($rendered['subject'])) {
$rendered['subject'] = trim(preg_replace('/[\r\n]+/', ' ', $rendered['subject']));
'tokenContext' => ['type' => 'array', 'for' => 'messageTemplate'],
'tplParams' => ['type' => 'array', 'for' => 'messageTemplate'],
'contactId' => ['type' => 'int|NULL', 'for' => 'messageTemplate' /* deprecated in favor of tokenContext[contactId] */],
+ 'workflow' => [
+ 'regex' => '/^([a-zA-Z_]+)$/',
+ 'type' => 'string',
+ 'for' => 'messageTemplate',
+ ],
'valueName' => [
'regex' => '/^([a-zA-Z_]+)$/',
'type' => 'string',
}
if ($context === 'messageTemplate') {
- $this->assertTrue(!empty($params['valueName']), "$msg: Message templates must always specify the name of the workflow step\n$dump");
+ $this->assertTrue(!empty($params['workflow']), "$msg: Message templates must always specify a symbolic name of the step/task\n$dump");
+ if (isset($params['valueName'])) {
+ // This doesn't require that valueName be supplied - but if it is supplied, it must match the workflow name.
+ $this->assertEquals($params['workflow'], $params['valueName'], "$msg: If given, workflow and valueName must match\n$dump");
+ }
$this->assertEquals($params['contactId'] ?? NULL, $params['tokenContext']['contactId'] ?? NULL, "$msg: contactId moved to tokenContext, but legacy value should be equivalent\n$dump");
// This assertion is surprising -- yet true. We should perhaps check if it was true in past releases...