2 * Implements hook_preprocess().
4 function {{ machine_name }}_preprocess(&$variables, $hook) {
7 // Add contextual links to the variables, if the user has permission.
9 if (!\Drupal::currentUser()->hasPermission('access contextual links')) {
14 $hooks = theme_get_registry();
17 // Determine the primary theme function argument.
18 if (isset($hooks[$hook]['variables'])) {
19 $keys = array_keys($hooks[$hook]['variables']);
23 $key = $hooks[$hook]['render element'];
26 if (isset($variables[$key])) {
27 $element = $variables[$key];
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';