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 db1fd93
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CRM/Contact/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Civi\Api4\Contact;
use Civi\Token\Event\TokenRegisterEvent;
use Civi\Token\Event\TokenValueEvent;
use Civi\Token\TokenException;
use Civi\Token\TokenProcessor;
use Civi\Token\TokenRow;

Expand Down Expand Up @@ -350,6 +351,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 db1fd93

Please sign in to comment.