Skip to content

Commit

Permalink
Fix token subscriber to format the display of the custom tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 15, 2021
1 parent a1cd8ab commit 6103e5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 2 additions & 5 deletions Civi/Token/TokenCompatSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function onEvaluate(TokenValueEvent $e) {
$params = [
['contact_id', '=', $contactId, 0, 0],
];
[$contact] = \CRM_Contact_BAO_Query::apiQuery($params);
[$contact] = \CRM_Contact_BAO_Query::apiQuery($params, array_fill_keys($messageTokens['contact'], 1));
//CRM-4524
$contact = reset($contact);
if (!$contact || is_a($contact, 'CRM_Core_Error')) {
Expand All @@ -71,10 +71,7 @@ public function onEvaluate(TokenValueEvent $e) {
if (!empty($messageTokens['contact'])) {
foreach ($messageTokens['contact'] as $token) {
if (\CRM_Core_BAO_CustomField::getKeyID($token)) {
$contact[$token] = civicrm_api3('Contact', 'getvalue', [
'return' => $token,
'id' => $contactId,
]);
$contact[$token] = \CRM_Core_BAO_CustomField::displayValue($contact[$token], \CRM_Core_BAO_CustomField::getKeyID($token));
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public function testContactTokens(): void {
public function testContactTokensRenderedByTokenProcessor(): void {
$this->createCustomGroupWithFieldsOfAllTypes([]);
$tokenData = $this->getAllContactTokens();
// @todo - these 2 still need fixing/ syncing.
unset($tokenData['preferred_communication_method'], $tokenData['addressee']);
// @todo - these still need fixing/ syncing.
unset($tokenData['preferred_communication_method'], $tokenData['addressee'], $tokenData['email_greeting'], $tokenData['postal_greeting']);
$address = $this->setupContactFromTokeData($tokenData);
$tokenString ='';
foreach (array_keys($tokenData) as $key) {
Expand All @@ -198,8 +198,11 @@ public function testContactTokensRenderedByTokenProcessor(): void {
$rendered = (string) $row->render('html');
}
$expected = $this->getExpectedContactOutput($address['id'], $tokenData, $rendered);
// @todo - fix these 2 & stop stripping them out.
$expected = str_replace(["preferred_communication_method:\n", "addressee:Mr. Robert Frank Smith II\n"], '', $expected);
// @todo - fix these & stop stripping them out.
$expected = str_replace([
"preferred_communication_method:\n",
"addressee:Mr. Robert Frank Smith II\n"
], '', $expected);
$this->assertEquals($expected, $rendered);
}

Expand Down

0 comments on commit 6103e5c

Please sign in to comment.