You are here

public function TestController::tokenReplace in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/token_test/src/Controller/TestController.php \Drupal\token_test\Controller\TestController::tokenReplace()

Provides a token replacement with a node as well as the current user.

This controller passes an explicit bubbleable metadata object to $this->token->replace(), and applies the collected metadata to the render array being built.

Parameters

\Drupal\node\NodeInterface $node: The node.

Return value

array The render array.

1 string reference to 'TestController::tokenReplace'
token_test.routing.yml in core/modules/system/tests/modules/token_test/token_test.routing.yml
core/modules/system/tests/modules/token_test/token_test.routing.yml

File

core/modules/system/tests/modules/token_test/src/Controller/TestController.php, line 59
Contains \Drupal\token_test\Controller\TestController.

Class

TestController
Provides a test controller for token replacement.

Namespace

Drupal\token_test\Controller

Code

public function tokenReplace(NodeInterface $node) {
  $bubbleable_metadata = new BubbleableMetadata();
  $build['#markup'] = $this->token
    ->replace('Tokens: [node:nid] [current-user:uid]', [
    'node' => $node,
  ], [], $bubbleable_metadata);
  $bubbleable_metadata
    ->applyTo($build);
  return $build;
}