-
Notifications
You must be signed in to change notification settings - Fork 1
/
asu_header.module
175 lines (157 loc) · 4.79 KB
/
asu_header.module
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* @file
* Contains asu_header.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function asu_header_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the asu_header module.
case 'help.page.asu_header':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Global header and footer for ASU web standards') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_menu_links_discovered_alter().
*/
function asu_header_menu_links_discovered_alter(&$links) {
$links['asu_header.logout']['class'] = 'Drupal\asu_header\Plugin\Menu\SigninSignoutMenuLink';
}
/**
* Implements hook_theme().
*/
function asu_header_theme($existing, $type, $theme, $path) {
$templates = $path . '/templates';
return [
'asu_footer' => [
'template' => 'asu-footer',
'variables' => [
'module_path' => NULL,
],
],
'menu__asu_global' => [
'base hook' => 'menu',
'render element' => 'menu',
],
'menu__main__mainnavigation' => [
'base hook' => 'menu',
'render element' => 'menu',
],
// The whole thing as one block doesn't quite work
// maybe mess with it later but it *works* with the
// separate templates so ignore it for now.
// 'asu_header' => [
// 'template' => 'asu-header',
// 'variables' => [
// 'module_path' => NULL,
// 'site_name' => NULL,
// 'site_slogan' => NULL,
// ],
// ],
'region__top_header' => [
'template' => 'region--top-header',
'render element' => 'content',
'path' => $templates,
'base hook' => 'region',
],
'block__asuglobalmenu' => [
'template' => 'block--asuglobalmenu',
'path' => $templates,
'base hook' => 'block',
'render element' => 'content',
],
'region__header' => [
'template' => 'region--header',
'render element' => 'content',
'path' => $templates,
'base hook' => 'region',
],
'block__system_menu_block__main' => [
'template' => 'block--system-menu-block--main',
'render element' => 'content',
'path' => $templates,
'base hook' => 'block',
'variables' => [
'module_path' => NULL,
'site_name' => NULL,
'site_slogan' => NULL,
],
],
];
}
/**
* Implements hook_preprocess_*()
* Pass the module path as a variable
*/
function asu_header_preprocess_asu_footer(&$variables, $hook) {
$module_handler = Drupal::service('module_handler');
$path = $module_handler->getModule('asu_header')->getPath();
$variables['module_path'] = $path;
}
/**
* Implements hook_preprocess_*()
* Pass the module path as a variable
*/
function asu_header_preprocess_block__system_menu_block__main(&$variables) {
/* Get module path and pass it as a variable */
$module_handler = Drupal::service('module_handler');
$path = $module_handler->getModule('asu_header')->getPath();
$variables['module_path'] = $path;
/* Get site info and pass those as variables */
$config = \Drupal::config('system.site');
$variables['site_name'] = $config->get('name');
$variables['site_slogan'] = $config->get('slogan');
}
/**
* Implements hook_preprocess_*()
* TODO: Count the number of nolink headings in the menu
* and pass that as a variable to the menu so we can alter
* the HTML for >2 columns.
*/
function asu_header_preprocess_menu(&$variables) {
/* Pass is_front variable to menu templates */
try {
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
}
catch (Exception $e) {
$variables['is_front'] = FALSE;
}
$variables['#cache']['contexts'][] = 'url.path.is_front';
/* Set is_active on item if the link matches current path */
$current_path = \Drupal::request()->getRequestUri();
foreach ($variables['items'] as &$item) {
if ($item['in_active_trail']) {
if ($item['url']->toString() == $current_path) {
$item['is_active'] = TRUE;
}
}
}
}
/**
* Implements hook_preprocess_*()
* Pass the module path as a variable
*/
//function asu_header_preprocess_asu_header(&$variables, $hook) {
// /* Get module path and pass it as a variable */
// $module_handler = Drupal::service('module_handler');
// $path = $module_handler->getModule('asu_header')->getPath();
// $variables['module_path'] = $path;
//
// /* Get site info and pass those as variables */
// $config = \Drupal::config('system.site');
// $variables['site_name'] = $config->get('name');
// $variables['site_slogan'] = $config->get('slogan');
//
//}
function asu_header_block_build_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
if ($block->getPluginId() === "system_menu_block:asu_global") {
$build['#cache']['contexts'][] = 'user';
}
}