Skip to content

Commit

Permalink
Remove call to getTokenDetails from Contribute pdf letter
Browse files Browse the repository at this point in the history
On digging this is just a glorifed api call. The parameters loaded are only used in emailLetter for filtering
  • Loading branch information
eileenmcnaughton committed Oct 14, 2021
1 parent 9cfd1a7 commit 1414550
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
15 changes: 6 additions & 9 deletions CRM/Contribute/Form/Task/PDFLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public function getTokenSchema(): array {
* @param bool $isIncludeSoftCredits
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public function buildContributionArray($groupBy, $contributionIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator, $isIncludeSoftCredits) {
$contributions = $contacts = [];
Expand Down Expand Up @@ -356,16 +357,12 @@ public function buildContributionArray($groupBy, $contributionIDs, $returnProper
// CiviMail, with a big performance impact.
// Hooks allow more nuanced smarty usage here.
CRM_Core_Smarty::singleton()->assign('contributions', $contributions);
$resolvedContacts = civicrm_api3('Contact', 'get', [
'return' => array_keys($returnProperties),
'id' => ['IN' => array_keys($contacts)],
])['values'];
foreach ($contacts as $contactID => $contact) {
[$tokenResolvedContacts] = CRM_Utils_Token::getTokenDetails(['contact_id' => $contactID],
$returnProperties,
$skipOnHold,
$skipDeceased,
NULL,
$messageToken,
$task
);
$contacts[$contactID] = array_merge($tokenResolvedContacts[$contactID], $contact);
$contacts[$contactID] = array_merge($resolvedContacts[$contactID], $contact);
}
return [$contributions, $contacts];
}
Expand Down
10 changes: 7 additions & 3 deletions tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public function testBuildContributionArray(): void {
[$contributions, $contacts] = $form->buildContributionArray('contact_id', $contributionIDs, $returnProperties, TRUE, TRUE, $messageToken, 'test', '**', FALSE);

$this->assertEquals('Anthony', $contacts[$this->_individualId]['first_name']);
$this->assertEquals('emo', $contacts[$this->_individualId]['favourite_emoticon']);
$this->assertEquals('Donation', $contributions[$result['id']]['financial_type']);
$this->assertEquals($campaignTitle, $contributions[$result['id']]['campaign']);
$this->assertEquals('Check', $contributions[$result['id']]['payment_instrument']);
Expand Down Expand Up @@ -261,14 +260,16 @@ public function testNoContributionTokens(): void {
/**
* Test all contribution tokens.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testAllContributionTokens(): void {
$this->hookClass->setHook('civicrm_tokenValues', [$this, 'hookTokenValues']);
$this->hookClass->setHook('civicrm_tokens', [$this, 'hook_tokens']);

$this->createLoggedInUser();
$this->createCustomGroupWithFieldsOfAllTypes(['extends' => 'Contribution']);
$this->campaignCreate(['name' => 'Big one', 'title' => 'Big one']);
$this->campaignCreate(['name' => 'Big one', 'title' => 'Big one'], FALSE);
$tokens = $this->getAllContributionTokens();
$formValues = [
'document_type' => 'pdf',
Expand All @@ -277,6 +278,7 @@ public function testAllContributionTokens(): void {
foreach (array_keys($this->getAllContributionTokens()) as $token) {
$formValues['html_message'] .= "$token : {contribution.$token}\n";
}
$formValues['html_message'] .= '{emoji.favourite_emoticon}';
/* @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_id:label']], $tokens))]);
Expand Down Expand Up @@ -326,6 +328,7 @@ public function testAllContributionTokens(): void {
' . $this->getCustomFieldName('multi_state') . ' : Victoria, New South Wales
' . $this->getCustomFieldName('boolean') . ' : Yes
' . $this->getCustomFieldName('checkbox') . ' : Purple
emo
</div>
</body>
</html>', $html);
Expand Down Expand Up @@ -513,6 +516,7 @@ public function testPostProcessGroupByContact(): void {
public function hook_tokens(&$tokens): void {
$this->hookTokensCalled++;
$tokens['aggregate'] = ['rendered_token' => 'rendered_token'];
$tokens['emoji'] = ['favourite_emoticon' => 'favourite_emoticon'];
}

/**
Expand Down

0 comments on commit 1414550

Please sign in to comment.