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
|
$items['admin/config/administration/adminimal_menu'] = array(
|
14
|
'title' => 'Adminimal menu',
|
15
|
'description' => 'Adjust adminimal menu settings.',
|
16
|
'page callback' => 'drupal_get_form',
|
17
|
'page arguments' => array('adminimal_admin_menu_settings'),
|
18
|
'access arguments' => array('administer site configuration'),
|
19
|
'file' => 'adminimal_menu_settings.inc',
|
20
|
);
|
21
|
|
22
|
return $items;
|
23
|
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
* Implements hook_page_build().
|
28
|
*/
|
29
|
function adminimal_admin_menu_page_build(&$page) {
|
30
|
if (!_adminimal_admin_menu_access()) {
|
31
|
return;
|
32
|
}
|
33
|
$path = drupal_get_path('module', 'adminimal_admin_menu');
|
34
|
$load_slicknav = variable_get('adminimal_admin_menu_slicknav', TRUE );
|
35
|
$load_jQuery = variable_get('adminimal_admin_menu_jquery', TRUE );
|
36
|
|
37
|
// Attach the CSS and JavaScript assets.
|
38
|
drupal_add_css($path . '/adminimal_admin_menu.css');
|
39
|
|
40
|
// Support for the Environment Indicator module.
|
41
|
if (module_exists('environment_indicator')) {
|
42
|
$environment_info = environment_indicator_get_active();
|
43
|
drupal_add_css('
|
44
|
div.slicknav_menu a.slicknav_btn:after {
|
45
|
content: "' . $environment_info['name']. '";
|
46
|
margin-left: 1em;
|
47
|
color: ' . $environment_info['text_color'] . ';
|
48
|
font-size: 12px;
|
49
|
background-color: ' . $environment_info['color'] . ';
|
50
|
padding: 2px 5px;
|
51
|
}
|
52
|
#admin-menu-wrapper {background: #222 !important;}
|
53
|
',
|
54
|
array(
|
55
|
'group' => CSS_DEFAULT,
|
56
|
'type' => 'inline',
|
57
|
'preprocess' => FALSE,
|
58
|
'weight' => '100',
|
59
|
));
|
60
|
}
|
61
|
|
62
|
// Check if both slicknav and custom jQuery must be loaded.
|
63
|
if ($load_slicknav and $load_jQuery) {
|
64
|
drupal_add_js($path . '/js/jquery.min.js', array( 'type' => 'file', 'scope' => 'header', 'weight' => 888 ));
|
65
|
drupal_add_js($path . '/js/slicknav/jquery-no-conflict.slicknav.js', array( 'type' => 'file', 'scope' => 'header', 'weight' => 888 ));
|
66
|
drupal_add_css($path . '/js/slicknav/slicknav.css');
|
67
|
}
|
68
|
elseif ($load_slicknav and !$load_jQuery) {
|
69
|
drupal_add_js($path . '/js/slicknav/jquery.slicknav.js', array( 'type' => 'file', 'scope' => 'header', 'weight' => 888 ));
|
70
|
drupal_add_css($path . '/js/slicknav/slicknav.css');
|
71
|
}
|
72
|
|
73
|
drupal_add_js($path . '/js/adminimal_admin_menu.js', array( 'type' => 'file', 'scope' => 'header', 'weight' => 888 ));
|
74
|
|
75
|
if (!isset($page['page_bottom']['admin_menu'])) {
|
76
|
return;
|
77
|
}
|
78
|
$attached = &$page['page_bottom']['admin_menu']['#attached'];
|
79
|
$options = array('every_page' => TRUE);
|
80
|
|
81
|
// @todo Stop-gap fix until cached rendering is resolved.
|
82
|
// @see http://drupal.org/node/1567622
|
83
|
if (module_exists('shortcut')) {
|
84
|
$attached['css'][drupal_get_path('module', 'shortcut') . '/shortcut.css'] = $options;
|
85
|
}
|
86
|
|
87
|
$settings = array();
|
88
|
// Add current path to support menu item highlighting.
|
89
|
// @todo Compile real active trail here?
|
90
|
$args = explode('/', $_GET['q']);
|
91
|
if ($args[0] == 'admin' && !empty($args[1])) {
|
92
|
$settings['activeTrail'] = url($args[0] . '/' . $args[1]);
|
93
|
}
|
94
|
elseif (drupal_is_front_page()) {
|
95
|
$settings['activeTrail'] = url('<front>');
|
96
|
}
|
97
|
|
98
|
$attached['js'][] = array(
|
99
|
'data' => array('admin_menu' => array('toolbar' => $settings)),
|
100
|
'type' => 'setting',
|
101
|
);
|
102
|
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* Implements hook_admin_menu_output_build().
|
107
|
*/
|
108
|
function adminimal_admin_menu_admin_menu_output_build(&$content) {
|
109
|
|
110
|
if (variable_get('adminimal_admin_menu_render', 'collapsed') != 'hidden') {
|
111
|
// Add shortcuts bar.
|
112
|
$content['shortcut'] = array(
|
113
|
'#access' => module_exists('shortcut'),
|
114
|
'#weight' => 200,
|
115
|
'#prefix' => '<div class="shortcut-toolbar">',
|
116
|
'#suffix' => '</div>',
|
117
|
);
|
118
|
$content['shortcut']['shortcuts'] = array(
|
119
|
// Shortcut module's CSS relies on Toolbar module's markup.
|
120
|
// @see http://drupal.org/node/1217038
|
121
|
'#prefix' => '<div id="toolbar">',
|
122
|
'#suffix' => '</div>',
|
123
|
// @todo Links may contain .active-trail classes.
|
124
|
'#pre_render' => array('shortcut_toolbar_pre_render'),
|
125
|
);
|
126
|
}
|
127
|
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* Implements hook_admin_menu_output_alter().
|
132
|
*/
|
133
|
function adminimal_admin_menu_admin_menu_output_alter(&$content) {
|
134
|
// Add a class to top-level items for styling.
|
135
|
foreach (element_children($content['menu']) as $link) {
|
136
|
$content['menu'][$link]['#attributes']['class'][] = 'admin-menu-toolbar-category';
|
137
|
}
|
138
|
|
139
|
// Alter icon.
|
140
|
unset($content['icon']['icon']['#theme']);
|
141
|
$content['icon']['icon']['#title'] = '<span class="admin-menu-home-icon"> </span>';
|
142
|
$content['icon']['icon']['#attributes']['class'][] = 'admin-menu-toolbar-home-menu';
|
143
|
$page['#attributes']['class'][] = 'adminimal-menu';
|
144
|
|
145
|
// Hide the menu.
|
146
|
if (variable_get('adminimal_admin_menu_render', 'collapsed') == 'exclusive') {
|
147
|
unset($content['icon']['icon']);
|
148
|
unset($content['search']);
|
149
|
foreach ($content['menu'] as $key => $link) {
|
150
|
// Move local tasks on 'admin' into icon menu.
|
151
|
unset($content['menu'][$key]);
|
152
|
}
|
153
|
}
|
154
|
|
155
|
// Create the responsive menu.
|
156
|
if (variable_get('adminimal_admin_menu_slicknav', 'TRUE')) {
|
157
|
// Prepare the responsive menu and Join the Icon menu with the administration menu.
|
158
|
$responsivemenu = array_merge($content['icon'], $content['menu']);
|
159
|
|
160
|
// Give it ID to target it later with js and css.
|
161
|
$responsivemenu['#wrapper_attributes']['id'] = 'admin-menu-menu-responsive';
|
162
|
|
163
|
// Move the icon menu to the top.
|
164
|
$responsivemenu['icon']['#weight'] = '-100';
|
165
|
|
166
|
// Change the link title to Administration.
|
167
|
$responsivemenu['admin/index']['#title'] = t('Administration');
|
168
|
|
169
|
// Bind the responsive menu the the content varable so it can be rendered.
|
170
|
$content['responsive-menu'] = $responsivemenu;
|
171
|
|
172
|
// Create the responsive shortucts.
|
173
|
$content['responsive']['shortcuts'] = array(
|
174
|
'#prefix' => '<div id="admin-menu-shortcuts-responsive">',
|
175
|
'#suffix' => '</div>',
|
176
|
'#pre_render' => array('shortcut_toolbar_pre_render'),
|
177
|
);
|
178
|
}
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
* Implements hook_preprocess_html().
|
183
|
*/
|
184
|
function adminimal_admin_menu_preprocess_html(&$vars) {
|
185
|
if (!_adminimal_admin_menu_access()) {
|
186
|
return;
|
187
|
}
|
188
|
// Add the "adminimal" class to the body for better css selection.
|
189
|
$vars['classes_array'][] = 'adminimal-menu';
|
190
|
|
191
|
// Add frontend and backend classes to the body.
|
192
|
if (path_is_admin(current_path())) {
|
193
|
$vars['classes_array'][] = 'adminimal-backend';
|
194
|
}
|
195
|
else {
|
196
|
$vars['classes_array'][] = 'adminimal-frontend';
|
197
|
}
|
198
|
|
199
|
// Add the shortcut render mode class.
|
200
|
$vars['classes_array'][] = 'menu-render-' . variable_get('adminimal_admin_menu_render', 'collapsed');
|
201
|
|
202
|
// Fix the viewport, correcting the mobile device zoom.
|
203
|
/** @todo - Mybre remove this and let the theme manage the view pont.
|
204
|
* But i was suprised that only few "responsive" drupal themes were fixing
|
205
|
* the viewport.
|
206
|
*/
|
207
|
$viewport = array(
|
208
|
'#tag' => 'meta',
|
209
|
'#attributes' => array(
|
210
|
'name' => 'viewport',
|
211
|
'content' => 'width=device-width, initial-scale=1, maximum-scale=1',
|
212
|
),
|
213
|
);
|
214
|
drupal_add_html_head($viewport, 'viewport');
|
215
|
|
216
|
}
|
217
|
|
218
|
/**
|
219
|
* Check if the user has access to use the admin menu.
|
220
|
* @return boolean Result of access checks.
|
221
|
*/
|
222
|
function _adminimal_admin_menu_access() {
|
223
|
if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
|
224
|
return FALSE;
|
225
|
}
|
226
|
|
227
|
// Performance: Skip this entirely for AJAX requests.
|
228
|
if (strpos($_GET['q'], 'js/') === 0) {
|
229
|
return FALSE;
|
230
|
}
|
231
|
return TRUE;
|
232
|
}
|