diff --git a/CRM/Contribute/Form/Task/PDFLetter.php b/CRM/Contribute/Form/Task/PDFLetter.php index 2804ae236baa..8b1142c32fee 100644 --- a/CRM/Contribute/Form/Task/PDFLetter.php +++ b/CRM/Contribute/Form/Task/PDFLetter.php @@ -546,19 +546,19 @@ public static function isValidHTMLWithTableSeparator($tokens, $html) { * @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 46aa8a889de8..4059e228a8e6 100644 --- a/Civi/Token/TokenRow.php +++ b/Civi/Token/TokenRow.php @@ -186,7 +186,7 @@ public function customToken($entity, $customFieldID, $entityID) { $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 859462228e1d..6cbc71de8ee1 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -297,19 +297,19 @@ public function testAllContributionTokens(): void {