8e35e7b9c124dd7a3cb1a41508053e5be80f717e
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / preprocess.twig
1 /**
2  * Implements hook_preprocess().
3  */
4 function {{ machine_name }}_preprocess(&$variables, $hook) {
5   static $hooks;
6
7   // Add contextual links to the variables, if the user has permission.
8
9   if (!\Drupal::currentUser()->hasPermission('access contextual links')) {
10     return;
11   }
12
13   if (!isset($hooks)) {
14     $hooks = theme_get_registry();
15   }
16
17   // Determine the primary theme function argument.
18   if (isset($hooks[$hook]['variables'])) {
19     $keys = array_keys($hooks[$hook]['variables']);
20     $key = $keys[0];
21   }
22   else {
23     $key = $hooks[$hook]['render element'];
24   }
25
26   if (isset($variables[$key])) {
27     $element = $variables[$key];
28   }
29
30   if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
31     $variables['title_suffix']['contextual_links'] = contextual_links_view($element);
32     if (!empty($variables['title_suffix']['contextual_links'])) {
33       $variables['attributes']['class'][] = 'contextual-links-region';
34     }
35   }
36 }