function TestController::tokenReplace

Same name in other branches
  1. 8.9.x core/modules/system/tests/modules/token_test/src/Controller/TestController.php \Drupal\token_test\Controller\TestController::tokenReplace()
  2. 10 core/modules/system/tests/modules/token_test/src/Controller/TestController.php \Drupal\token_test\Controller\TestController::tokenReplace()
  3. 11.x 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 53

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.