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" . '
-contribution_id : 1 +id : 1 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 : Check +payment_instrument_id:label : Check trxn_id : 1234 invoice_id : 568 currency : EUR @@ -311,11 +310,11 @@ public function testAllContributionTokens(): void { cancel_reason : Contribution Cancel Reason receipt_date : October 30th, 2019 12:00 AM thankyou_date : 2019-11-30 00:00:00 -contribution_source : Contribution Source +source : Contribution Source amount_level : Amount Level contribution_status_id : 2 check_number : 6789 -campaign : Big one +campaign_id:label : Big one ' . $this->getCustomFieldName('text') . ' : Bobsled ' . $this->getCustomFieldName('select_string') . ' : Red ' . $this->getCustomFieldName('select_date') . ' : 01/20/2021 12:00AM @@ -337,17 +336,16 @@ public function testAllContributionTokens(): void { * Get all the tokens available to contributions. * * @return array - * @throws \CiviCRM_API3_Exception */ public function getAllContributionTokens(): array { return [ - 'contribution_id' => '', + 'id' => '', 'total_amount' => '9999.99', 'fee_amount' => '1111.11', 'net_amount' => '7777.78', 'non_deductible_amount' => '2222.22', 'receive_date' => '2018-07-20', - 'payment_instrument' => 'Check', + 'payment_instrument_id:label' => 'Check', 'trxn_id' => '1234', 'invoice_id' => '568', 'currency' => 'EUR', @@ -355,11 +353,11 @@ public function getAllContributionTokens(): array { 'cancel_reason' => 'Contribution Cancel Reason', 'receipt_date' => '2019-10-30', 'thankyou_date' => '2019-11-30', - 'contribution_source' => 'Contribution Source', + 'source' => 'Contribution Source', 'amount_level' => 'Amount Level', 'contribution_status_id' => 'Pending', 'check_number' => '6789', - 'campaign' => 'Big one', + 'campaign_id:label' => 'Big one', $this->getCustomFieldName('text') => 'Bobsled', $this->getCustomFieldName('select_string') => 'R', $this->getCustomFieldName('select_date') => '2021-01-20', @@ -373,7 +371,6 @@ public function getAllContributionTokens(): array { $this->getCustomFieldName('boolean') => TRUE, $this->getCustomFieldName('checkbox') => 'P', $this->getCustomFieldName('contact_reference') => $this->individualCreate(['first_name' => 'Spider', 'last_name' => 'Man']), - ]; } @@ -675,6 +672,7 @@ protected function createContribution(array $contributionParams = []) { 'contact_id' => $this->individualCreate(), 'total_amount' => 100, 'financial_type_id' => 'Donation', + 'source' => 'Contribution Source', ], $contributionParams); return $this->callAPISuccess('Contribution', 'create', $contributionParams)['id']; }