From: Eileen McNaughton Date: Sat, 18 Sep 2021 01:00:22 +0000 (+1200) Subject: Remove calls to replaceContributionTokens X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9a88bc66471ee0f3d83ae35b481dceb8532e3077;p=civicrm-core.git Remove calls to replaceContributionTokens --- diff --git a/CRM/Contribute/Form/Task/PDFLetter.php b/CRM/Contribute/Form/Task/PDFLetter.php index 828227dc66..1d2f9b845d 100644 --- a/CRM/Contribute/Form/Task/PDFLetter.php +++ b/CRM/Contribute/Form/Task/PDFLetter.php @@ -546,19 +546,19 @@ class CRM_Contribute_Form_Task_PDFLetter extends CRM_Contribute_Form_Task { * @return string */ protected function resolveTokens(string $html_message, $contact, $contribution, $messageToken, $grouped, $separator, $contributions): string { - if ($grouped) { - $tokenHtml = CRM_Utils_Token::replaceMultipleContributionTokens($separator, $html_message, $contributions, $messageToken); - } - else { - // no change to normal behaviour to avoid risk of breakage - $tokenHtml = CRM_Utils_Token::replaceContributionTokens($html_message, $contribution, TRUE, $messageToken); - } $tokenContext = [ 'smarty' => (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY), 'contactId' => $contact['contact_id'], ]; + if ($grouped) { + $html_message = CRM_Utils_Token::replaceMultipleContributionTokens($separator, $html_message, $contributions, $messageToken); + } + else { + $tokenContext['schema'] = ['contributionId']; + $tokenContext['contributionId'] = $contribution['id']; + } $smarty = ['contact' => $contact]; - return CRM_Core_TokenSmarty::render(['html' => $tokenHtml], $tokenContext, $smarty)['html']; + return CRM_Core_TokenSmarty::render(['html' => $html_message], $tokenContext, $smarty)['html']; } } diff --git a/Civi/Token/TokenRow.php b/Civi/Token/TokenRow.php index 41b6462749..96ea178166 100644 --- a/Civi/Token/TokenRow.php +++ b/Civi/Token/TokenRow.php @@ -186,7 +186,7 @@ class TokenRow { $fieldValue = \CRM_Core_BAO_CustomField::displayValue($fieldValue, $customFieldID); } - return $this->tokens($entity, $customFieldName, $fieldValue); + return $this->format('text/html')->tokens($entity, $customFieldName, $fieldValue); } /** diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index 859462228e..6cbc71de8e 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -297,19 +297,19 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase {
id : 1 -total_amount : € 9,999.99 -fee_amount : € 1,111.11 -net_amount : € 7,777.78 -non_deductible_amount : € 2,222.22 +total_amount : € 9,999.99 +fee_amount : € 1,111.11 +net_amount : € 7,777.78 +non_deductible_amount : € 2,222.22 receive_date : July 20th, 2018 12:00 AM payment_instrument_id:label : Check trxn_id : 1234 invoice_id : 568 currency : EUR -cancel_date : 2019-12-30 00:00:00 +cancel_date : December 30th, 2019 12:00 AM cancel_reason : Contribution Cancel Reason receipt_date : October 30th, 2019 12:00 AM -thankyou_date : 2019-11-30 00:00:00 +thankyou_date : November 30th, 2019 12:00 AM source : Contribution Source amount_level : Amount Level contribution_status_id : 2