civi.token.list¶
Summary¶
This event is dispatched when listing/registering tokens
Definition¶
This event is dispatched via the Symfony EventDispatcher.
public static function onTokenList(\Civi\Token\Event\TokenRegisterEvent $event): void
Parameters¶
\Civi\Token\Event\TokenRegisterEvent $event
Event Methods¶
entity(string $entity):\Civi\Token\Event\TokenRegisterEvent- Returns the TokenRegisterEvent with the specified entity as the default entityregister(array|string $paramsOrField, $label):\Civi\Token\Event\TokenRegisterEvent- Registers the token, if passing in an array as the first parameter you need two keys if you have chained this to an entity call - field the machine name for the token and the label which is human readable label dispayed in the token picker. If your calling register directly without calling entity first you need to include a 3rd parameter which is the entity that this token is for
Event Properties¶
Example¶
use Civi\Token\Event\TokenRegisterEvent;
public static function onTokenlist(TokenRegisterEvent $event): void {
// register tokens on the profile entity
$event->entity('profile')
->register('viewUrl', ts('Default Profile URL (View Mode)')
->register('editUrl', ts('Default Profile URL (Edit Mode)');
// Register tokens on profile event without calling the entity function
$event->register([
'entity' => 'profile',
'field' => 'viewUrl',
'label' => ts('Default Profile URL (View Mode)'),
]);
}