diff vendor/chi-teck/drupal-code-generator/templates/d8/hook/preprocess.twig @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/preprocess.twig	Thu Jul 05 14:24:15 2018 +0000
@@ -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';
+    }
+  }
+}