Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / tokens_alter.twig
1 /**
2  * Implements hook_tokens_alter().
3  */
4 function {{ machine_name }}_tokens_alter(array &$replacements, array $context) {
5   $options = $context['options'];
6
7   if (isset($options['language'])) {
8     $url_options['language'] = $options['language'];
9     $language_code = $options['language']->language;
10   }
11   else {
12     $language_code = NULL;
13   }
14   $sanitize = !empty($options['sanitize']);
15
16   if ($context['type'] == 'node' && !empty($context['data']['node'])) {
17     $node = $context['data']['node'];
18
19     // Alter the [node:title] token, and replace it with the rendered content
20     // of a field (field_title).
21     if (isset($context['tokens']['title'])) {
22       $title = field_view_field('node', $node, 'field_title', 'default', $language_code);
23       $replacements[$context['tokens']['title']] = drupal_render($title);
24     }
25   }
26 }