Aller au contenu

Home > Developer Guide > Hooks and events > Token Hooks/listeners

civi.token.eval

Summary

This event is dispatched when evaluating tokens

Definition

This event is dispatched via the Symfony EventDispatcher.

public static function onTokenList(\Civi\Token\Event\TokenValueEvent $event): void

Parameters

  • \Civi\Token\Event\TokenValueEvent $event

Event Methods

  • getRows: \Traversable<\Civi\Token\TokenRow> - Returns the TokenRows that are being evaluated

Example

/**
 * Rewrite contact first name
 */
public static function evaluateTokens(\Civi\Token\Event\TokenValueEvent $e): void {

  $tokens = $e->getTokenProcessor()->getMessageTokens();

  if (!isset($tokens['contact'])) {
    return;
  }

  foreach ($e->getRows() as $row) {
    if (in_array('first_name', $tokens['contact'])) {
      $row->format('text/html');
      $row->tokens('contact', 'first_name', 'Rewritten First Name');
    }
  }
}