Mercurial > hg > cmmr2012-drupal-site
annotate vendor/chi-teck/drupal-code-generator/templates/d7/hook/tokens_alter.twig @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | c75dbcec494b |
children |
rev | line source |
---|---|
Chris@0 | 1 /** |
Chris@0 | 2 * Implements hook_tokens_alter(). |
Chris@0 | 3 */ |
Chris@0 | 4 function {{ machine_name }}_tokens_alter(array &$replacements, array $context) { |
Chris@0 | 5 $options = $context['options']; |
Chris@0 | 6 |
Chris@0 | 7 if (isset($options['language'])) { |
Chris@0 | 8 $url_options['language'] = $options['language']; |
Chris@0 | 9 $language_code = $options['language']->language; |
Chris@0 | 10 } |
Chris@0 | 11 else { |
Chris@0 | 12 $language_code = NULL; |
Chris@0 | 13 } |
Chris@0 | 14 $sanitize = !empty($options['sanitize']); |
Chris@0 | 15 |
Chris@0 | 16 if ($context['type'] == 'node' && !empty($context['data']['node'])) { |
Chris@0 | 17 $node = $context['data']['node']; |
Chris@0 | 18 |
Chris@0 | 19 // Alter the [node:title] token, and replace it with the rendered content |
Chris@0 | 20 // of a field (field_title). |
Chris@0 | 21 if (isset($context['tokens']['title'])) { |
Chris@0 | 22 $title = field_view_field('node', $node, 'field_title', 'default', $language_code); |
Chris@0 | 23 $replacements[$context['tokens']['title']] = drupal_render($title); |
Chris@0 | 24 } |
Chris@0 | 25 } |
Chris@0 | 26 } |