2 * Implements hook_tokens_alter().
4 function {{ machine_name }}_tokens_alter(array &$replacements, array $context, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {
5 $options = $context['options'];
7 if (isset($options['langcode'])) {
8 $url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
9 $langcode = $options['langcode'];
15 if ($context['type'] == 'node' && !empty($context['data']['node'])) {
16 $node = $context['data']['node'];
18 // Alter the [node:title] token, and replace it with the rendered content
19 // of a field (field_title).
20 if (isset($context['tokens']['title'])) {
21 $title = $node->field_title->view('default');
22 $replacements[$context['tokens']['title']] = drupal_render($title);