You are here

public function ExampleTokenEventSubscriber::tokenInfo in Hook Event Dispatcher 8

Provides new token types and tokens.

Parameters

\Drupal\hook_event_dispatcher\Event\Token\TokensInfoEvent $event: The token info event.

File

src/Example/ExampleTokenEventSubscriber.php, line 33

Class

ExampleTokenEventSubscriber
Class ExampleTokenEventSubscriber.

Namespace

Drupal\hook_event_dispatcher\Example

Code

public function tokenInfo(TokensInfoEvent $event) {

  // The node type already exists, but it's just an example how to add a type.
  $type = TokenType::create('node', t('Node'))
    ->setDescription('Node tokens')
    ->setNeedsData('node');
  $event
    ->addTokenType($type);

  // Add node token.
  $event
    ->addToken(Token::create('node', 'serialized', t('Serialized string of the node'))
    ->setDescription('Node serialized'));
}