function token_block_view_alter in Token 8
Same name and namespace in other branches
- 7 token.module \token_block_view_alter()
Implements hook_block_view_alter().
File
- ./
token.module, line 76 - Enhances the token API in core: adds a browseable UI, missing tokens, etc.
Code
function token_block_view_alter(&$build, BlockPluginInterface $block) {
if (isset($build['#configuration'])) {
$label = $build['#configuration']['label'];
if ($label != '<none>') {
// The label is automatically escaped, avoid escaping it twice.
// @todo https://www.drupal.org/node/2580723 will add a method or option
// to the token API to do this, use that when available.
$bubbleable_metadata = BubbleableMetadata::createFromRenderArray($build);
$build['#configuration']['label'] = PlainTextOutput::renderFromHtml(\Drupal::token()
->replace($label, [], [], $bubbleable_metadata));
$bubbleable_metadata
->applyTo($build);
}
}
}