diff --git a/CRM/Contribute/WorkflowMessage/RecurringCancelled.php b/CRM/Contribute/WorkflowMessage/RecurringCancelled.php index 2ffdfc14cdde..93c39e53b05a 100644 --- a/CRM/Contribute/WorkflowMessage/RecurringCancelled.php +++ b/CRM/Contribute/WorkflowMessage/RecurringCancelled.php @@ -19,8 +19,22 @@ class CRM_Contribute_WorkflowMessage_RecurringCancelled extends Civi\WorkflowMes */ public $contact; + /** + * Export tokens to smarty as variables. + * + * The key represents the smarty token and the value is the token as + * requested from the token processor. + * + * The token is 'the entire part between the curly quotes' eg. + * + * '{contribution_recur.amount|crmMoney}. + * + * Unlike using the contribution directly it will default to 'raw' formatting. + * + * @param array $export + */ protected function exportExtraTokenContext(array &$export): void { - $export['smartyTokenAlias']['amount'] = 'contribution_recur.amount'; + $export['smartyTokenAlias']['amount'] = 'contribution_recur.amount|crmMoney'; $export['smartyTokenAlias']['recur_frequency_unit'] = 'contribution_recur.frequency_unit:label'; $export['smartyTokenAlias']['recur_frequency_interval'] = 'contribution_recur.frequency_interval'; } diff --git a/CRM/Contribute/WorkflowMessage/RecurringEdit.php b/CRM/Contribute/WorkflowMessage/RecurringEdit.php index 7e211c87244e..495db5c5b729 100644 --- a/CRM/Contribute/WorkflowMessage/RecurringEdit.php +++ b/CRM/Contribute/WorkflowMessage/RecurringEdit.php @@ -33,13 +33,32 @@ class CRM_Contribute_WorkflowMessage_RecurringEdit extends Civi\WorkflowMessage\ */ public $receiptFromEmail; + /** + * Export tokens to smarty as variables. + * + * The key represents the smarty token and the value is the token as + * requested from the token processor. + * + * The token is 'the entire part between the curly quotes' eg. + * + * '{contribution_recur.amount|crmMoney}. + * + * Unlike using the contribution directly it will default to 'raw' formatting. + * + * @param array $export + */ protected function exportExtraTokenContext(array &$export): void { $export['smartyTokenAlias']['installments'] = 'contribution_recur.installments'; - $export['smartyTokenAlias']['amount'] = 'contribution_recur.amount'; + $export['smartyTokenAlias']['amount'] = 'contribution_recur.amount|crmMoney'; $export['smartyTokenAlias']['recur_frequency_unit'] = 'contribution_recur.frequency_unit:label'; $export['smartyTokenAlias']['recur_frequency_interval'] = 'contribution_recur.frequency_interval'; } + /** + * Extra variables to be exported to smarty based on being calculated. + * + * @param array $export + */ protected function exportExtraTplParams(array &$export): void { if (empty($export['receipt_from_email']) && !empty($this->from)) { // At a minimum, we can at least autofill 'receipt_from_email' in the case where it's missing. diff --git a/Civi/Token/TokenCompatSubscriber.php b/Civi/Token/TokenCompatSubscriber.php index 6274d8f29c39..b349f9c3808c 100644 --- a/Civi/Token/TokenCompatSubscriber.php +++ b/Civi/Token/TokenCompatSubscriber.php @@ -70,9 +70,18 @@ public function onRender(TokenRenderEvent $e): void { if ($useSmarty) { $smartyVars = []; foreach ($e->context['smartyTokenAlias'] ?? [] as $smartyName => $tokenName) { - $smartyVars[$smartyName] = \CRM_Utils_Array::pathGet($e->row->tokens, explode('.', $tokenName), $e->context['locale'] ?? NULL); + $tokenParts = explode('|', $tokenName); + $modifier = $tokenParts[1] ?? ''; + $smartyVars[$smartyName] = \CRM_Utils_Array::pathGet($e->row->tokens, explode('.', $tokenParts[0]), $e->context['locale'] ?? NULL); if ($smartyVars[$smartyName] instanceof \Brick\Money\Money) { - $smartyVars[$smartyName] = \Civi::format()->money($smartyVars[$smartyName]->getAmount(), $smartyVars[$smartyName]->getCurrency()); + // TODO: We should reuse the filters from TokenProcessor::filterTokenValue() + if ($modifier === 'crmMoney') { + $smartyVars[$smartyName] = \Civi::format() + ->money($smartyVars[$smartyName]->getAmount(), $smartyVars[$smartyName]->getCurrency()); + } + else { + $smartyVars[$smartyName] = $smartyVars[$smartyName]->getAmount(); + } } } \CRM_Core_Smarty::singleton()->pushScope($smartyVars);