Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / tokens_alter.twig
1 /**
2  * Implements hook_tokens_alter().
3  */
4 function {{ machine_name }}_tokens_alter(array &$replacements, array $context, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {
5   $options = $context['options'];
6
7   if (isset($options['langcode'])) {
8     $url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
9     $langcode = $options['langcode'];
10   }
11   else {
12     $langcode = NULL;
13   }
14
15   if ($context['type'] == 'node' && !empty($context['data']['node'])) {
16     $node = $context['data']['node'];
17
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);
23     }
24   }
25 }