X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FEvent%2FParticipantTokens.php;h=b29050fcf143fd24f98f5fdfba01af4557788751;hb=8055c8995f696e969db5286fa2d1446d9c8261e8;hp=f33af5d2b5458d1847a1525c0c3b28927be1c515;hpb=30b363bc83efc6cd0e2f3f8f018d0a29bfc47495;p=civicrm-core.git diff --git a/CRM/Event/ParticipantTokens.php b/CRM/Event/ParticipantTokens.php index f33af5d2b5..b29050fcf1 100644 --- a/CRM/Event/ParticipantTokens.php +++ b/CRM/Event/ParticipantTokens.php @@ -10,7 +10,6 @@ +--------------------------------------------------------------------+ */ -use Civi\Token\Event\TokenValueEvent; use Civi\Token\TokenRow; /** @@ -20,13 +19,6 @@ use Civi\Token\TokenRow; */ class CRM_Event_ParticipantTokens extends CRM_Core_EntityTokens { - public static function getSubscribedEvents() { - $events = parent::getSubscribedEvents(); - // Set the weight so it runs before event tokens. - $events['civi.token.eval'] = ['evaluateTokens', 400]; - return $events; - } - /** * Get the entity name for api v4 calls. * @@ -43,21 +35,6 @@ class CRM_Event_ParticipantTokens extends CRM_Core_EntityTokens { return ['fee_currency']; } - /** - * To handle variable tokens, override this function and return the active tokens. - * - * @param \Civi\Token\Event\TokenValueEvent $e - * - * @return mixed - */ - public function getActiveTokens(TokenValueEvent $e) { - $messageTokens = $e->getTokenProcessor()->getMessageTokens(); - if (!isset($messageTokens[$this->entity])) { - return isset($messageTokens['event']) ? ['event_id'] : FALSE; - } - return parent::getActiveTokens($e); - } - /** * Get any tokens with custom calculation. */ @@ -74,15 +51,20 @@ class CRM_Event_ParticipantTokens extends CRM_Core_EntityTokens { ]; } + public function alterActionScheduleQuery(\Civi\ActionSchedule\Event\MailingQueryEvent $e): void { + // When targeting `civicrm_participant` records, we enable both `{participant.*}` (per usual) and the related `{event.*}`. + parent::alterActionScheduleQuery($e); + if ($e->mapping->getEntity() === $this->getExtendableTableName()) { + $e->query->select('e.event_id AS tokenContext_eventId'); + } + } + /** * @inheritDoc * @throws \CiviCRM_API3_Exception */ public function evaluateToken(TokenRow $row, $entity, $field, $prefetch = NULL) { $this->prefetch = (array) $prefetch; - if (empty($row->context['eventId'])) { - $row->context['eventId'] = $this->getFieldValue($row, 'event_id'); - } if ($field === 'balance') { // @todo - is this really a good idea to call this & potentially get the // balance of the contribution attached to 'registered_by_id' @@ -111,7 +93,7 @@ class CRM_Event_ParticipantTokens extends CRM_Core_EntityTokens { * * @return string[] */ - public function getSkippedFields(): array { + protected function getSkippedFields(): array { $fields = parent::getSkippedFields(); // Never add these 2 fields - may not be a stable part of the schema. // This field is on it's way out of core.