1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Themes Administration menu like Adminimal theme.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_menu().
|
10
|
*/
|
11
|
function adminimal_admin_menu_menu() {
|
12
|
$items = array();
|
13
|
|
14
|
$items['admin/config/administration/adminimal_menu'] = array(
|
15
|
'title' => 'Adminimal menu',
|
16
|
'description' => 'Adjust adminimal menu settings.',
|
17
|
'page callback' => 'drupal_get_form',
|
18
|
'page arguments' => array('adminimal_admin_menu_settings'),
|
19
|
'access arguments' => array('administer site configuration'),
|
20
|
'file' => 'adminimal_admin_menu.admin.inc',
|
21
|
);
|
22
|
|
23
|
return $items;
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
* Implements hook_module_implements_alter().
|
28
|
*/
|
29
|
function adminimal_admin_menu_module_implements_alter(&$implementations, $hook) {
|
30
|
// Put Adminimal Admin Menu's implementation of hook_admin_menu_output_alter()
|
31
|
// to the end of the list of implementors, assuring that it will be executed
|
32
|
// at the very end. Other modules may manipulate the menu items in the
|
33
|
// administration menu (i.e. the excellent Administration Menu Source) and we
|
34
|
// need to make sure those changes are preserved and respected by the output
|
35
|
// of Adminimal Admin Menu.
|
36
|
if ($hook == 'admin_menu_output_alter') {
|
37
|
$group = $implementations['adminimal_admin_menu'];
|
38
|
unset($implementations['adminimal_admin_menu']);
|
39
|
$implementations['adminimal_admin_menu'] = $group;
|
40
|
}
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Implements hook_page_build().
|
45
|
*/
|
46
|
function adminimal_admin_menu_page_build(&$page) {
|
47
|
if (!_adminimal_admin_menu_access()) {
|
48
|
return;
|
49
|
}
|
50
|
$path = drupal_get_path('module', 'adminimal_admin_menu');
|
51
|
$load_slicknav = variable_get('adminimal_admin_menu_slicknav', TRUE);
|
52
|
$load_jquery = variable_get('adminimal_admin_menu_jquery', TRUE);
|
53
|
|
54
|
// Attach the CSS and JavaScript assets.
|
55
|
drupal_add_css($path . '/adminimal_admin_menu.css');
|
56
|
|
57
|
_adminimal_admin_menu_support_environment_indicator();
|
58
|
|
59
|
// Check if both slicknav and custom jQuery must be loaded.
|
60
|
if ($load_slicknav and $load_jquery) {
|
61
|
drupal_add_js($path . '/js/jquery.min.js', array(
|
62
|
'type' => 'file',
|
63
|
'scope' => 'header',
|
64
|
'weight' => 888,
|
65
|
));
|
66
|
drupal_add_js($path . '/js/slicknav/jquery-no-conflict.slicknav.js', array(
|
67
|
'type' => 'file',
|
68
|
'scope' => 'header',
|
69
|
'weight' => 888,
|
70
|
));
|
71
|
drupal_add_css($path . '/js/slicknav/slicknav.css');
|
72
|
}
|
73
|
elseif ($load_slicknav and !$load_jquery) {
|
74
|
drupal_add_js($path . '/js/slicknav/jquery.slicknav.js', array(
|
75
|
'type' => 'file',
|
76
|
'scope' => 'header',
|
77
|
'weight' => 888,
|
78
|
));
|
79
|
drupal_add_css($path . '/js/slicknav/slicknav.css');
|
80
|
}
|
81
|
|
82
|
drupal_add_js($path . '/js/adminimal_admin_menu.js', array(
|
83
|
'type' => 'file',
|
84
|
'scope' => 'header',
|
85
|
'weight' => 888,
|
86
|
));
|
87
|
|
88
|
if (!isset($page['page_bottom']['admin_menu'])) {
|
89
|
return;
|
90
|
}
|
91
|
$attached = &$page['page_bottom']['admin_menu']['#attached'];
|
92
|
$options = array('every_page' => TRUE);
|
93
|
|
94
|
// @todo Stop-gap fix until cached rendering is resolved (http://drupal.org/node/1567622).
|
95
|
if (module_exists('shortcut')) {
|
96
|
$attached['css'][drupal_get_path('module', 'shortcut') . '/shortcut.css'] = $options;
|
97
|
}
|
98
|
|
99
|
$settings = array();
|
100
|
// Add current path to support menu item highlighting.
|
101
|
// @todo Compile real active trail here?
|
102
|
$args = explode('/', $_GET['q']);
|
103
|
if ($args[0] == 'admin' && !empty($args[1])) {
|
104
|
$settings['activeTrail'] = url($args[0] . '/' . $args[1]);
|
105
|
}
|
106
|
elseif (drupal_is_front_page()) {
|
107
|
$settings['activeTrail'] = url('<front>');
|
108
|
}
|
109
|
|
110
|
$attached['js'][] = array(
|
111
|
'data' => array('admin_menu' => array('toolbar' => $settings)),
|
112
|
'type' => 'setting',
|
113
|
);
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Add CSS for module environment_indicator.
|
118
|
*/
|
119
|
function _adminimal_admin_menu_support_environment_indicator() {
|
120
|
if (!module_exists('environment_indicator')) {
|
121
|
return;
|
122
|
}
|
123
|
|
124
|
$environment_info = environment_indicator_get_active();
|
125
|
|
126
|
if (!environment_indicator_check_access($environment_info)) {
|
127
|
return;
|
128
|
}
|
129
|
|
130
|
drupal_add_css('
|
131
|
div.slicknav_menu a.slicknav_btn:after {
|
132
|
content: "' . $environment_info['name'] . '";
|
133
|
margin-left: 1em;
|
134
|
color: ' . $environment_info['text_color'] . ';
|
135
|
font-size: 12px;
|
136
|
background-color: ' . $environment_info['color'] . ';
|
137
|
padding: 2px 5px;
|
138
|
}
|
139
|
#admin-menu-wrapper {background: #222 !important;}
|
140
|
',
|
141
|
array(
|
142
|
'group' => CSS_DEFAULT,
|
143
|
'type' => 'inline',
|
144
|
'preprocess' => FALSE,
|
145
|
'weight' => '100',
|
146
|
));
|
147
|
}
|
148
|
|
149
|
/**
|
150
|
* Implements hook_admin_menu_output_build().
|
151
|
*/
|
152
|
function adminimal_admin_menu_admin_menu_output_build(&$content) {
|
153
|
|
154
|
// Shortcut menu.
|
155
|
if (module_exists('shortcut') && variable_get('adminimal_admin_menu_render', 'collapsed') != 'hidden') {
|
156
|
// Add shortcuts bar.
|
157
|
$content['shortcut'] = array(
|
158
|
'#access' => module_exists('shortcut'),
|
159
|
'#weight' => 200,
|
160
|
'#prefix' => '<div class="shortcut-toolbar">',
|
161
|
'#suffix' => '</div>',
|
162
|
);
|
163
|
$content['shortcut']['shortcuts'] = array(
|
164
|
// Shortcut module's CSS relies on Toolbar module's markup.
|
165
|
// @see http://drupal.org/node/1217038
|
166
|
'#prefix' => '<div id="toolbar">',
|
167
|
'#suffix' => '</div>',
|
168
|
// @todo Links may contain .active-trail classes.
|
169
|
'#pre_render' => array('shortcut_toolbar_pre_render'),
|
170
|
);
|
171
|
}
|
172
|
}
|
173
|
|
174
|
/**
|
175
|
* Implements hook_admin_menu_output_alter().
|
176
|
*/
|
177
|
function adminimal_admin_menu_admin_menu_output_alter(&$content) {
|
178
|
// Add a class to top-level items for styling.
|
179
|
foreach (element_children($content['menu']) as $link) {
|
180
|
$content['menu'][$link]['#attributes']['class'][] = 'admin-menu-toolbar-category';
|
181
|
}
|
182
|
|
183
|
// Alter icon.
|
184
|
unset($content['icon']['icon']['#theme']);
|
185
|
$content['icon']['icon']['#title'] = '<span class="admin-menu-home-icon"> </span>';
|
186
|
$content['icon']['icon']['#attributes']['class'][] = 'admin-menu-toolbar-home-menu';
|
187
|
// @todo Fix this CS-issue.
|
188
|
$page['#attributes']['class'][] = 'adminimal-menu';
|
189
|
|
190
|
// Hide the menu.
|
191
|
if (module_exists('shortcut') && variable_get('adminimal_admin_menu_render', 'collapsed') == 'exclusive') {
|
192
|
unset($content['icon']['icon']);
|
193
|
unset($content['search']);
|
194
|
foreach ($content['menu'] as $key => $link) {
|
195
|
// Move local tasks on 'admin' into icon menu.
|
196
|
unset($content['menu'][$key]);
|
197
|
}
|
198
|
}
|
199
|
|
200
|
// Create the responsive menu.
|
201
|
if (variable_get('adminimal_admin_menu_slicknav', TRUE)) {
|
202
|
// Join the Icon menu with the administration menu.
|
203
|
$responsivemenu = array_merge($content['icon'], $content['menu']);
|
204
|
|
205
|
// Give it ID to target it later with js and css.
|
206
|
$responsivemenu['#wrapper_attributes']['id'] = 'admin-menu-menu-responsive';
|
207
|
|
208
|
// Move the icon menu to the top.
|
209
|
$responsivemenu['icon']['#weight'] = '-100';
|
210
|
|
211
|
// Change the link title for 'admin/index' to Administration if it exists.
|
212
|
if (!empty($responsivemenu['admin/index'])) {
|
213
|
$responsivemenu['admin/index']['#title'] = t('Administration');
|
214
|
}
|
215
|
|
216
|
// Add the account menu, and push account and logout links toward bottom.
|
217
|
$responsivemenu = array_merge($content['account'], $responsivemenu);
|
218
|
$responsivemenu['account']['#weight'] = 99;
|
219
|
$responsivemenu['logout']['#weight'] = 100;
|
220
|
|
221
|
// Bind the responsive menu the the content varable so it can be rendered.
|
222
|
$content['responsive-menu'] = $responsivemenu;
|
223
|
|
224
|
// Create the responsive shortucts.
|
225
|
if (module_exists('shortcut')) {
|
226
|
$content['responsive']['shortcuts'] = array(
|
227
|
'#prefix' => '<div id="admin-menu-shortcuts-responsive">',
|
228
|
'#suffix' => '</div>',
|
229
|
'#pre_render' => array('shortcut_toolbar_pre_render'),
|
230
|
);
|
231
|
}
|
232
|
}
|
233
|
}
|
234
|
|
235
|
/**
|
236
|
* Implements hook_preprocess_html().
|
237
|
*/
|
238
|
function adminimal_admin_menu_preprocess_html(&$vars) {
|
239
|
if (!_adminimal_admin_menu_access()) {
|
240
|
return;
|
241
|
}
|
242
|
|
243
|
// Add the "adminimal" class to the body for better css selection.
|
244
|
$vars['classes_array'][] = 'adminimal-menu';
|
245
|
|
246
|
// Add frontend and backend classes to the body.
|
247
|
if (path_is_admin(current_path())) {
|
248
|
$vars['classes_array'][] = 'adminimal-backend';
|
249
|
}
|
250
|
else {
|
251
|
$vars['classes_array'][] = 'adminimal-frontend';
|
252
|
}
|
253
|
|
254
|
// Add the shortcut render mode class.
|
255
|
if (module_exists('shortcut')) {
|
256
|
$vars['classes_array'][] = 'menu-render-' . variable_get('adminimal_admin_menu_render', 'collapsed');
|
257
|
}
|
258
|
|
259
|
_adminimal_admin_menu_viewport();
|
260
|
}
|
261
|
|
262
|
/**
|
263
|
* Add viewport for scaling on devices.
|
264
|
*/
|
265
|
function _adminimal_admin_menu_viewport() {
|
266
|
$use_slicknav = variable_get('adminimal_admin_menu_slicknav', TRUE);
|
267
|
$use_viewport = variable_get('adminimal_admin_menu_viewport', TRUE);
|
268
|
|
269
|
// Only needed for slicknav.
|
270
|
if ($use_slicknav && $use_viewport) {
|
271
|
$viewport = array(
|
272
|
'#tag' => 'meta',
|
273
|
'#attributes' => array(
|
274
|
'name' => 'viewport',
|
275
|
'content' => 'width=device-width, initial-scale=1',
|
276
|
),
|
277
|
);
|
278
|
drupal_add_html_head($viewport, 'viewport');
|
279
|
}
|
280
|
}
|
281
|
|
282
|
/**
|
283
|
* Check if the user has access to use the admin menu.
|
284
|
*
|
285
|
* @return bool
|
286
|
* Result of access checks.
|
287
|
*/
|
288
|
function _adminimal_admin_menu_access() {
|
289
|
if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
|
290
|
return FALSE;
|
291
|
}
|
292
|
|
293
|
// Performance: Skip this entirely for AJAX requests.
|
294
|
if (strpos($_GET['q'], 'js/') === 0) {
|
295
|
return FALSE;
|
296
|
}
|
297
|
return TRUE;
|
298
|
}
|