public function TestController::tokenReplace in Drupal 8
Same name and namespace in other branches
- 9 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\ControllerCode
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;
}