X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Fpreprocess.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Fpreprocess.twig;h=8e35e7b9c124dd7a3cb1a41508053e5be80f717e;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/preprocess.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/preprocess.twig new file mode 100644 index 000000000..8e35e7b9c --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/preprocess.twig @@ -0,0 +1,36 @@ +/** + * Implements hook_preprocess(). + */ +function {{ machine_name }}_preprocess(&$variables, $hook) { + static $hooks; + + // Add contextual links to the variables, if the user has permission. + + if (!\Drupal::currentUser()->hasPermission('access contextual links')) { + return; + } + + if (!isset($hooks)) { + $hooks = theme_get_registry(); + } + + // Determine the primary theme function argument. + if (isset($hooks[$hook]['variables'])) { + $keys = array_keys($hooks[$hook]['variables']); + $key = $keys[0]; + } + else { + $key = $hooks[$hook]['render element']; + } + + if (isset($variables[$key])) { + $element = $variables[$key]; + } + + if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) { + $variables['title_suffix']['contextual_links'] = contextual_links_view($element); + if (!empty($variables['title_suffix']['contextual_links'])) { + $variables['attributes']['class'][] = 'contextual-links-region'; + } + } +}