Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / preprocess.twig
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 (file)
index 0000000..8e35e7b
--- /dev/null
@@ -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';
+    }
+  }
+}