X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd7%2Fhook%2Ftokens_alter.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd7%2Fhook%2Ftokens_alter.twig;h=b6014496c4c0fffb092e776093d3fbd6ccd8b165;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/tokens_alter.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/tokens_alter.twig new file mode 100644 index 000000000..b6014496c --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/tokens_alter.twig @@ -0,0 +1,26 @@ +/** + * Implements hook_tokens_alter(). + */ +function {{ machine_name }}_tokens_alter(array &$replacements, array $context) { + $options = $context['options']; + + if (isset($options['language'])) { + $url_options['language'] = $options['language']; + $language_code = $options['language']->language; + } + else { + $language_code = NULL; + } + $sanitize = !empty($options['sanitize']); + + if ($context['type'] == 'node' && !empty($context['data']['node'])) { + $node = $context['data']['node']; + + // Alter the [node:title] token, and replace it with the rendered content + // of a field (field_title). + if (isset($context['tokens']['title'])) { + $title = field_view_field('node', $node, 'field_title', 'default', $language_code); + $replacements[$context['tokens']['title']] = drupal_render($title); + } + } +}