Skip to content

Commit

Permalink
Avoid extra queries when prefix_id:label is a token
Browse files Browse the repository at this point in the history
Because the value was not populating the array it kept getting it over & over
  • Loading branch information
eileenmcnaughton committed Aug 3, 2022
1 parent cf0015d commit d2c423f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CRM/Contact/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function evaluateLegacyHookTokens(TokenValueEvent $e): void {
*
* @param \Civi\Token\Event\TokenValueEvent $e
*
* @throws TokenException
* @throws \Civi\Token\TokenException
* @throws \CRM_Core_Exception
*/
public function onEvaluate(TokenValueEvent $e) {
Expand Down Expand Up @@ -350,6 +350,15 @@ protected function getFieldValue(TokenRow $row, string $field) {
if (isset($row->context[$entityName][$possibility])) {
return $row->context[$entityName][$possibility];
}
if ($this->isPseudoField($possibility)) {
// If we have a name or label field & already have the id loaded then we can
// evaluate from that rather than query again.
$split = explode(':', $possibility);
if (isset($row->context[$entityName][$split[0]])) {
$row->context[$entityName][$possibility] = $this->getPseudoValue($split[0], $split[1], $row->context[$entityName][$split[0]]);
return $row->context[$entityName][$possibility];
}
}
}
$contactID = $this->getFieldValue($row, 'id');
if ($contactID) {
Expand Down

0 comments on commit d2c423f

Please sign in to comment.