You are here

public function ExampleTokenEventSubscriber::tokenReplacement in Hook Event Dispatcher 3.x

Same name and namespace in other branches
  1. 8.2 examples/ExampleTokenEventSubscriber.php \Drupal\hook_event_dispatcher\ExampleTokenEventSubscriber::tokenReplacement()

Replace tokens.

Parameters

\Drupal\core_event_dispatcher\Event\Token\TokensReplacementEvent $event: The token replacement event.

Throws

\UnexpectedValueException

File

examples/ExampleTokenEventSubscriber.php, line 65

Class

ExampleTokenEventSubscriber
Class ExampleTokenEventSubscriber.

Namespace

Drupal\hook_event_dispatcher

Code

public function tokenReplacement(TokensReplacementEvent $event) : void {
  if ($event
    ->forToken('node', 'serialized')) {
    $event
      ->setReplacementValue('node', 'serialized', serialize($event
      ->getData('node')));
  }
}