Projet

Général

Profil

Paste
Télécharger (4,27 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / adminimal_admin_menu / adminimal_admin_menu.module @ 87dbc3bf

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

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

    
39
  if (!isset($page['page_bottom']['admin_menu'])) {
40
    return;
41
  }
42
  $attached = &$page['page_bottom']['admin_menu']['#attached'];
43
  $options = array('every_page' => TRUE);
44

    
45
  // @todo Stop-gap fix until cached rendering is resolved.
46
  // @see http://drupal.org/node/1567622
47
  if (module_exists('shortcut')) {
48
    $attached['css'][drupal_get_path('module', 'shortcut') . '/shortcut.css'] = $options;
49
  }
50

    
51
  $settings = array();
52
  // Add current path to support menu item highlighting.
53
  // @todo Compile real active trail here?
54
  $args = explode('/', $_GET['q']);
55
  if ($args[0] == 'admin' && !empty($args[1])) {
56
    $settings['activeTrail'] = url($args[0] . '/' . $args[1]);
57
  }
58
  elseif (drupal_is_front_page()) {
59
    $settings['activeTrail'] = url('<front>');
60
  }
61

    
62
  $attached['js'][] = array(
63
    'data' => array('admin_menu' => array('toolbar' => $settings)),
64
    'type' => 'setting',
65
  );
66
}
67

    
68
/**
69
 * Implements hook_admin_menu_output_build().
70
 */
71
function adminimal_admin_menu_admin_menu_output_build(&$content) {
72

    
73
  if (variable_get('adminimal_admin_menu_render', 'collapsed') != 'hidden') {
74
    // Add shortcuts bar.
75
    $content['shortcut'] = array(
76
      '#access' => module_exists('shortcut'),
77
      '#weight' => 200,
78
      '#prefix' => '<div class="shortcut-toolbar">',
79
      '#suffix' => '</div>',
80
    );
81
    $content['shortcut']['shortcuts'] = array(
82
      // Shortcut module's CSS relies on Toolbar module's markup.
83
      // @see http://drupal.org/node/1217038
84
      '#prefix' => '<div id="toolbar">',
85
      '#suffix' => '</div>',
86
      // @todo Links may contain .active-trail classes.
87
      '#pre_render' => array('shortcut_toolbar_pre_render'),
88
    );
89
  }
90

    
91
}
92

    
93
/**
94
 * Implements hook_admin_menu_output_alter().
95
 */
96
function adminimal_admin_menu_admin_menu_output_alter(&$content) {
97
  // Add a class to top-level items for styling.
98
  foreach (element_children($content['menu']) as $link) {
99
    $content['menu'][$link]['#attributes']['class'][] = 'admin-menu-toolbar-category';
100
  }
101

    
102
  // Alter icon.
103
  unset($content['icon']['icon']['#theme']);
104
  $content['icon']['icon']['#title'] = '<span class="admin-menu-home-icon">&nbsp;</span>';
105
  $content['icon']['icon']['#attributes']['class'][] = 'admin-menu-toolbar-home-menu';
106
  $page['#attributes']['class'][] = 'adminimal-menu';
107

    
108
  // Hide the menu.
109
  if (variable_get('adminimal_admin_menu_render', 'collapsed') == 'exclusive') {
110
    unset($content['icon']['icon']);
111
    unset($content['search']);
112
    foreach ($content['menu'] as $key => $link) {
113
      // Move local tasks on 'admin' into icon menu.
114
      unset($content['menu'][$key]);
115
    }
116
  }
117
}
118

    
119
/**
120
 * Implements hook_preprocess_html().
121
 */
122
function adminimal_admin_menu_preprocess_html(&$vars) {
123
  if (!_adminimal_admin_menu_access()) {
124
    return;
125
  }
126
  // Add the "adminimal" class to the body for better css selection.
127
  $vars['classes_array'][] = 'adminimal-menu';
128

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

    
132
}
133

    
134
/**
135
 * Check if the user has access to use the admin menu.
136
 * @return  boolean Result of access checks.
137
 */
138
function _adminimal_admin_menu_access() {
139
  if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
140
    return FALSE;
141
  }
142

    
143
  // Performance: Skip this entirely for AJAX requests.
144
  if (strpos($_GET['q'], 'js/') === 0) {
145
    return FALSE;
146
  }
147
  return TRUE;
148
}