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