diff --git a/CRM/Contact/Form/Task/EmailTrait.php b/CRM/Contact/Form/Task/EmailTrait.php index 4bfa01b407fe..91041e3f8189 100644 --- a/CRM/Contact/Form/Task/EmailTrait.php +++ b/CRM/Contact/Form/Task/EmailTrait.php @@ -692,6 +692,10 @@ public static function deprecatedTokensFormRule(array $fields) { $deprecatedTokens = [ '{case.status_id}' => '{case.status_id:label}', '{case.case_type_id}' => '{case.case_type_id:label}', + '{contribution.campaign}' => '{contribution.campaign_id:label}', + '{contribution.payment_instrument}' => '{contribution.payment_instrument_id:label}', + '{contribution.contribution_id}' => '{contribution.id}', + '{contribution.contribution_source}' => '{contribution.source}', ]; $tokenErrors = []; foreach ($deprecatedTokens as $token => $replacement) { diff --git a/CRM/Core/Form/Task/PDFLetterCommon.php b/CRM/Core/Form/Task/PDFLetterCommon.php index c98886324b72..f267a10d8569 100644 --- a/CRM/Core/Form/Task/PDFLetterCommon.php +++ b/CRM/Core/Form/Task/PDFLetterCommon.php @@ -209,6 +209,10 @@ public static function formRule($fields, $files, $self) { '{case.case_type_id}' => '{case.case_type_id:label}', '{membership.status}' => '{membership.status_id:label}', '{membership.type}' => '{membership.membership_type_id:label}', + '{contribution.campaign}' => '{contribution.campaign_id:label}', + '{contribution.payment_instrument}' => '{contribution.payment_instrument_id:label}', + '{contribution.contribution_id}' => '{contribution.id}', + '{contribution.contribution_source}' => '{contribution.source}', ]; $tokenErrors = []; foreach ($deprecatedTokens as $token => $replacement) { diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index d7d3dfdac3bf..39397d6b59c8 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -1786,7 +1786,7 @@ public static function getMembershipTokenReplacement($entity, $token, $membershi * @return mixed|string * @throws \CRM_Core_Exception */ - public static function getContributionTokenReplacement($token, &$contribution, $html = FALSE, $escapeSmarty = FALSE) { + public static function getContributionTokenReplacement($token, $contribution, $html = FALSE, $escapeSmarty = FALSE) { self::_buildContributionTokens(); switch ($token) { @@ -1807,6 +1807,10 @@ public static function getContributionTokenReplacement($token, &$contribution, $ $value = CRM_Utils_Date::customFormat($value, $config->dateformatDatetime); break; + case 'source': + $value = CRM_Utils_Array::retrieveValueRecursive($contribution, 'contribution_source'); + break; + default: if (!in_array($token, self::$_tokens['contribution'])) { $value = "{contribution.$token}"; diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index 2c90ca30dcec..859462228e1d 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -265,7 +265,6 @@ public function testNoContributionTokens(): void { * @throws \API_Exception * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception - * @throws \Civi\API\Exception\UnauthorizedException */ public function testAllContributionTokens(): void { $this->createLoggedInUser(); @@ -281,7 +280,7 @@ public function testAllContributionTokens(): void { } /* @var $form CRM_Contribute_Form_Task_PDFLetter */ $form = $this->getFormObject('CRM_Contribute_Form_Task_PDFLetter', $formValues); - $form->setContributionIds([$this->createContribution(array_merge(['campaign_id' => $tokens['campaign']], $tokens))]); + $form->setContributionIds([$this->createContribution(array_merge(['campaign_id' => $tokens['campaign_id:label']], $tokens))]); try { $form->postProcess(); } @@ -297,13 +296,13 @@ public function testAllContributionTokens(): void { ' . " \n" . '