forked from skilld-labs/zen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zen.theme
88 lines (76 loc) · 2.85 KB
/
zen.theme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* @file
* Contains functions to alter Drupal's markup for the Zen theme.
*
* IMPORTANT WARNING: DO NOT MODIFY THIS FILE.
*
* The base Zen theme is designed to be easily extended by its sub-themes. You
* shouldn't modify this or any of the CSS or PHP files in the root zen/ folder.
* See the online documentation for more information:
* https://drupal.org/documentation/theme/zen
*/
// Auto-rebuild the theme registry during theme development.
if (theme_get_setting('zen_rebuild_registry') && !defined('MAINTENANCE_MODE')) {
// Rebuild .info.yml data and clear Twig cache.
$theme_handler = \Drupal::service('theme_handler');
$theme_handler->refreshInfo();
// Rebuild theme registry.
// @TODO Clear the theme registry.
// $theme_registry = \Drupal::service('theme.registry');
// $theme_registry->reset();
// $theme_registry->get();
// @TODO: Turn on Twig debugging. Though its probably impossible from a theme.
// $GLOBALS['conf']['theme_debug'] = TRUE;
}
/**
* Implements HOOK_theme().
*/
function zen_theme(&$existing, $type, $theme, $path) {
include_once './' . drupal_get_path('theme', 'zen') . '/zen-internals/theme-registry.inc';
return _zen_theme($existing, $type, $theme, $path);
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function zen_theme_suggestions_page_alter(array &$suggestions, array $variables) {
// If on an individual node page, add the node type to theme suggestions.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$first_suggestion = array_shift($suggestions);
array_unshift($suggestions, 'page__node__' . $node->bundle());
if ($first_suggestion) {
array_unshift($suggestions, $first_suggestion);
}
if (in_array('page__node__edit', $suggestions)) {
$suggestions[] = 'page__node__edit__' . $node->bundle();
}
}
}
/**
* Implements hook_pre_render_HOOK() for menu-local-tasks templates.
*
* Use preprocess hook to convert menu_local_task into variables needed by the
* tabs component.
*/
function zen_preprocess_menu_local_tasks(&$variables) {
foreach (array('primary', 'secondary') as $type) {
$tabs = array();
// Sort the tabs by #weight.
uasort($variables[$type], array('Drupal\Component\Utility\SortArray', 'sortByWeightProperty'));
foreach (array_keys($variables[$type]) as $key) {
// Add the tab to a new array.
$tabs[$key] = array(
'active' => $variables[$type][$key]['#active'],
'url' => $variables[$type][$key]['#link']['url']->toString(),
'text' => \Drupal\Component\Utility\Html::escape($variables[$type][$key]['#link']['title'])
);
// Check if the tab should be shown by rendering the original.
$link = drupal_render($variables[$type][$key]);
if (!$link) {
unset($tabs[$key]);
}
}
// Overwrite the original tabs data.
$variables[$type] = $tabs;
}
}