From 8ea4b051768e2ea5d33561d8635e40ae23a79561 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Mon, 25 Apr 2016 09:46:01 +1200 Subject: [PATCH] CRM-18465 fully resolve contributions before resolving tokens --- CRM/Contribute/Form/Task/PDFLetterCommon.php | 27 +++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/CRM/Contribute/Form/Task/PDFLetterCommon.php b/CRM/Contribute/Form/Task/PDFLetterCommon.php index 5605905207..bd87f08561 100644 --- a/CRM/Contribute/Form/Task/PDFLetterCommon.php +++ b/CRM/Contribute/Form/Task/PDFLetterCommon.php @@ -230,6 +230,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF $task ); $contribution = $contributions[$contributionId] = $contribution[$contributionId]; + if ($form->_includesSoftCredits) { //@todo find out why this happens & add comments list($contactID) = explode('-', $item); @@ -239,15 +240,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF $contactID = $contribution['contact_id']; } if (!isset($contacts[$contactID])) { - list($contact) = CRM_Utils_Token::getTokenDetails(array('contact_id' => $contactID), - $returnProperties, - $skipOnHold, - $skipDeceased, - NULL, - $messageToken, - $task - ); - $contacts[$contactID] = $contact[$contactID]; + $contacts[$contactID] = array(); $contacts[$contactID]['contact_aggregate'] = 0; $contacts[$contactID]['combined'] = $contacts[$contactID]['contribution_ids'] = array(); } @@ -265,6 +258,22 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF $contacts[$contactID]['aggregates'][$groupBy][$groupByID] += $contribution['total_amount']; } } + // Assign the available contributions before calling tokens so hooks parsing smarty can access it. + // Note that in core code you can only use smarty here if enable if for the whole site, incl + // CiviMail, with a big performance impact. + // Hooks allow more nuanced smarty usage here. + CRM_Core_Smarty::singleton()->assign('contributions', $contributions); + foreach ($contacts as $contactID => $contact) { + $tokenResolvedContacts = CRM_Utils_Token::getTokenDetails(array('contact_id' => $contactID), + $returnProperties, + $skipOnHold, + $skipDeceased, + NULL, + $messageToken, + $task + ); + $contacts[$contactID] = array_merge($tokenResolvedContacts[0][$contactID], $contact); + } return array($contributions, $contacts); } -- 2.25.1