2 * Implements hook_tokens_alter().
4 function {{ machine_name }}_tokens_alter(array &$replacements, array $context) {
5 $options = $context['options'];
7 if (isset($options['language'])) {
8 $url_options['language'] = $options['language'];
9 $language_code = $options['language']->language;
12 $language_code = NULL;
14 $sanitize = !empty($options['sanitize']);
16 if ($context['type'] == 'node' && !empty($context['data']['node'])) {
17 $node = $context['data']['node'];
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);