Projet

Général

Profil

Paste
Télécharger (8,03 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / adminimal_admin_menu / adminimal_admin_menu.module @ c304a780

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
 * Implements hook_page_build().
27
 */
28
function adminimal_admin_menu_page_build(&$page) {
29
  if (!_adminimal_admin_menu_access()) {
30
    return;
31
  }
32
  $path = drupal_get_path('module', 'adminimal_admin_menu');
33
  $load_slicknav = variable_get('adminimal_admin_menu_slicknav', TRUE);
34
  $load_jquery = variable_get('adminimal_admin_menu_jquery', TRUE);
35

    
36
  // Attach the CSS and JavaScript assets.
37
  drupal_add_css($path . '/adminimal_admin_menu.css');
38

    
39
  _adminimal_admin_menu_support_environment_indicator();
40

    
41
  // Check if both slicknav and custom jQuery must be loaded.
42
  if ($load_slicknav and $load_jquery) {
43
    drupal_add_js($path . '/js/jquery.min.js', array(
44
      'type' => 'file',
45
      'scope' => 'header',
46
      'weight' => 888,
47
    ));
48
    drupal_add_js($path . '/js/slicknav/jquery-no-conflict.slicknav.js', array(
49
      'type' => 'file',
50
      'scope' => 'header',
51
      'weight' => 888,
52
    ));
53
    drupal_add_css($path . '/js/slicknav/slicknav.css');
54
  }
55
  elseif ($load_slicknav and !$load_jquery) {
56
    drupal_add_js($path . '/js/slicknav/jquery.slicknav.js', array(
57
      'type' => 'file',
58
      'scope' => 'header',
59
      'weight' => 888,
60
    ));
61
    drupal_add_css($path . '/js/slicknav/slicknav.css');
62
  }
63

    
64
  drupal_add_js($path . '/js/adminimal_admin_menu.js', array(
65
    'type' => 'file',
66
    'scope' => 'header',
67
    'weight' => 888,
68
  ));
69

    
70
  if (!isset($page['page_bottom']['admin_menu'])) {
71
    return;
72
  }
73
  $attached = &$page['page_bottom']['admin_menu']['#attached'];
74
  $options = array('every_page' => TRUE);
75

    
76
  // @todo Stop-gap fix until cached rendering is resolved.
77
  // @see http://drupal.org/node/1567622
78
  if (module_exists('shortcut')) {
79
    $attached['css'][drupal_get_path('module', 'shortcut') . '/shortcut.css'] = $options;
80
  }
81

    
82
  $settings = array();
83
  // Add current path to support menu item highlighting.
84
  // @todo Compile real active trail here?
85
  $args = explode('/', $_GET['q']);
86
  if ($args[0] == 'admin' && !empty($args[1])) {
87
    $settings['activeTrail'] = url($args[0] . '/' . $args[1]);
88
  }
89
  elseif (drupal_is_front_page()) {
90
    $settings['activeTrail'] = url('<front>');
91
  }
92

    
93
  $attached['js'][] = array(
94
    'data' => array('admin_menu' => array('toolbar' => $settings)),
95
    'type' => 'setting',
96
  );
97
}
98

    
99
/**
100
 * Add CSS for module environment_indicator.
101
 */
102
function _adminimal_admin_menu_support_environment_indicator() {
103
  if (!module_exists('environment_indicator')) {
104
    return;
105
  }
106

    
107
  $environment_info = environment_indicator_get_active();
108

    
109
  if (!environment_indicator_check_access($environment_info)) {
110
    return;
111
  }
112

    
113
  drupal_add_css('
114
      div.slicknav_menu a.slicknav_btn:after {
115
        content: "' . $environment_info['name'] . '";
116
        margin-left: 1em;
117
        color: ' . $environment_info['text_color'] . ';
118
        font-size: 12px;
119
        background-color: ' . $environment_info['color'] . ';
120
        padding: 2px 5px;
121
      }
122
      #admin-menu-wrapper {background: #222 !important;}
123
      ',
124
    array(
125
      'group' => CSS_DEFAULT,
126
      'type' => 'inline',
127
      'preprocess' => FALSE,
128
      'weight' => '100',
129
    ));
130
}
131

    
132
/**
133
 * Implements hook_admin_menu_output_build().
134
 */
135
function adminimal_admin_menu_admin_menu_output_build(&$content) {
136

    
137
  if (variable_get('adminimal_admin_menu_render', 'collapsed') != 'hidden') {
138
    // Add shortcuts bar.
139
    $content['shortcut'] = array(
140
      '#access' => module_exists('shortcut'),
141
      '#weight' => 200,
142
      '#prefix' => '<div class="shortcut-toolbar">',
143
      '#suffix' => '</div>',
144
    );
145
    $content['shortcut']['shortcuts'] = array(
146
      // Shortcut module's CSS relies on Toolbar module's markup.
147
      // @see http://drupal.org/node/1217038
148
      '#prefix' => '<div id="toolbar">',
149
      '#suffix' => '</div>',
150
      // @todo Links may contain .active-trail classes.
151
      '#pre_render' => array('shortcut_toolbar_pre_render'),
152
    );
153
  }
154

    
155
}
156

    
157
/**
158
 * Implements hook_admin_menu_output_alter().
159
 */
160
function adminimal_admin_menu_admin_menu_output_alter(&$content) {
161
  // Add a class to top-level items for styling.
162
  foreach (element_children($content['menu']) as $link) {
163
    $content['menu'][$link]['#attributes']['class'][] = 'admin-menu-toolbar-category';
164
  }
165

    
166
  // Alter icon.
167
  unset($content['icon']['icon']['#theme']);
168
  $content['icon']['icon']['#title'] = '<span class="admin-menu-home-icon">&nbsp;</span>';
169
  $content['icon']['icon']['#attributes']['class'][] = 'admin-menu-toolbar-home-menu';
170
  // @todo Fix this CS-issue.
171
  $page['#attributes']['class'][] = 'adminimal-menu';
172

    
173
  // Hide the menu.
174
  if (variable_get('adminimal_admin_menu_render', 'collapsed') == 'exclusive') {
175
    unset($content['icon']['icon']);
176
    unset($content['search']);
177
    foreach ($content['menu'] as $key => $link) {
178
      // Move local tasks on 'admin' into icon menu.
179
      unset($content['menu'][$key]);
180
    }
181
  }
182

    
183
  // Create the responsive menu.
184
  if (variable_get('adminimal_admin_menu_slicknav', TRUE)) {
185
    // Join the Icon menu with the administration menu.
186
    $responsivemenu = array_merge($content['icon'], $content['menu']);
187

    
188
    // Give it ID to target it later with js and css.
189
    $responsivemenu['#wrapper_attributes']['id'] = 'admin-menu-menu-responsive';
190

    
191
    // Move the icon menu to the top.
192
    $responsivemenu['icon']['#weight'] = '-100';
193

    
194
    // Change the link title for 'admin/index' to Administration if it exists.
195
    if (!empty($responsivemenu['admin/index'])) {
196
      $responsivemenu['admin/index']['#title'] = t('Administration');
197
    }
198

    
199
    // Add the account menu, and push account and logout links toward bottom.
200
    $responsivemenu = array_merge($content['account'], $responsivemenu);
201
    $responsivemenu['account']['#weight'] = 99;
202
    $responsivemenu['logout']['#weight'] = 100;
203

    
204
    // Bind the responsive menu the the content varable so it can be rendered.
205
    $content['responsive-menu'] = $responsivemenu;
206

    
207
    // Create the responsive shortucts.
208
    $content['responsive']['shortcuts'] = array(
209
      '#prefix' => '<div id="admin-menu-shortcuts-responsive">',
210
      '#suffix' => '</div>',
211
      '#pre_render' => array('shortcut_toolbar_pre_render'),
212
    );
213
  }
214
}
215

    
216
/**
217
 * Implements hook_preprocess_html().
218
 */
219
function adminimal_admin_menu_preprocess_html(&$vars) {
220
  if (!_adminimal_admin_menu_access()) {
221
    return;
222
  }
223
  // Add the "adminimal" class to the body for better css selection.
224
  $vars['classes_array'][] = 'adminimal-menu';
225

    
226
  // Add frontend and backend classes to the body.
227
  if (path_is_admin(current_path())) {
228
    $vars['classes_array'][] = 'adminimal-backend';
229
  }
230
  else {
231
    $vars['classes_array'][] = 'adminimal-frontend';
232
  }
233

    
234
  // Add the shortcut render mode class.
235
  $vars['classes_array'][] = 'menu-render-' . variable_get('adminimal_admin_menu_render', 'collapsed');
236

    
237
  /*
238
   * Fix the viewport, correcting the mobile device zoom.
239
   *
240
   * @todo Maybe remove this and let the theme manage the view point.
241
   *   But i was suprised that only few "responsive" drupal themes were fixing
242
   *   the viewport.
243
   */
244
  $viewport = array(
245
    '#tag' => 'meta',
246
    '#attributes' => array(
247
      'name' => 'viewport',
248
      'content' => 'width=device-width, initial-scale=1, maximum-scale=1',
249
    ),
250
  );
251
  drupal_add_html_head($viewport, 'viewport');
252

    
253
}
254

    
255
/**
256
 * Check if the user has access to use the admin menu.
257
 *
258
 * @return bool
259
 *   Result of access checks.
260
 */
261
function _adminimal_admin_menu_access() {
262
  if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
263
    return FALSE;
264
  }
265

    
266
  // Performance: Skip this entirely for AJAX requests.
267
  if (strpos($_GET['q'], 'js/') === 0) {
268
    return FALSE;
269
  }
270
  return TRUE;
271
}