forked from a64f7bb4-7358-4778-9fbe-3b882c34cc1d/v1
16 lines
614 B
Twig
16 lines
614 B
Twig
/**
|
|
* Implements hook_tokens_alter().
|
|
*/
|
|
function {{ machine_name }}_tokens_alter(array &$replacements, array $context, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {
|
|
if ($context['type'] == 'node' && !empty($context['data']['node'])) {
|
|
$node = $context['data']['node'];
|
|
|
|
// Alter the [node:title] token, and replace it with the rendered content
|
|
// of a field (field_title).
|
|
if (isset($context['tokens']['title'])) {
|
|
$title = $node->field_title->view('default');
|
|
$replacements[$context['tokens']['title']] = \Drupal::service('renderer')->render($title);
|
|
}
|
|
}
|
|
}
|