Projet

Général

Profil

Paste
Télécharger (3,79 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / admin_menu / admin_menu_toolbar / admin_menu_toolbar.module @ c8d66f01

1
<?php
2

    
3
/**
4
 * @file
5
 * Renders Administration menu like Toolbar (core) module.
6
 *
7
 * @todo Separate shortcut functionality into own module/widget.
8
 */
9

    
10
/**
11
 * Implements hook_form_FORMID_alter().
12
 */
13
function admin_menu_toolbar_form_admin_menu_theme_settings_alter(&$form) {
14
  // Add the shortcut links as component on behalf of Shortcut module.
15
  $form['plugins']['admin_menu_components']['#options']['shortcut.links'] = t('Shortcuts');
16
  // The shortcut bar consists of two elements, so we target their class names
17
  // instead of cluttering the markup with additional IDs.
18
  $form['plugins']['admin_menu_components']['shortcut.links']['#attributes']['rel'] = '.shortcut-toggle, .shortcut-toolbar';
19
}
20

    
21
/**
22
 * Implementation of hook_page_build().
23
 */
24
function admin_menu_toolbar_page_build(&$page) {
25
  if (!isset($page['page_bottom']['admin_menu'])) {
26
    return;
27
  }
28
  $path = drupal_get_path('module', 'admin_menu_toolbar');
29
  $attached = &$page['page_bottom']['admin_menu']['#attached'];
30
  $options = array('every_page' => TRUE);
31

    
32
  $attached['css'][$path . '/admin_menu_toolbar.css'] = $options;
33
  $attached['js'][$path . '/admin_menu_toolbar.js'] = $options;
34

    
35
  // @todo Stop-gap fix until cached rendering is resolved.
36
  // @see http://drupal.org/node/1567622
37
  if (module_exists('shortcut')) {
38
    $attached['css'][drupal_get_path('module', 'shortcut') . '/shortcut.css'] = $options;
39
  }
40

    
41
  $settings = array();
42
  // Add current path to support menu item highlighting.
43
  // @todo Compile real active trail here?
44
  $args = explode('/', $_GET['q']);
45
  if ($args[0] == 'admin' && !empty($args[1])) {
46
    $settings['activeTrail'] = url($args[0] . '/' . $args[1]);
47
  }
48
  elseif (drupal_is_front_page()) {
49
    $settings['activeTrail'] = url('<front>');
50
  }
51

    
52
  $attached['js'][] = array(
53
    'data' => array('admin_menu' => array('toolbar' => $settings)),
54
    'type' => 'setting',
55
  );
56
}
57

    
58
/**
59
 * Implements hook_admin_menu_output_build().
60
 */
61
function admin_menu_toolbar_admin_menu_output_build(&$content) {
62
  if (empty($content['#components']['shortcut.links']) && !$content['#complete']) {
63
    return;
64
  }
65
  // Add shortcuts toggle.
66
  $content['shortcut-toggle'] = array(
67
    '#access' => module_exists('shortcut'),
68
    '#weight' => -200,
69
    '#type' => 'link',
70
    '#title' => t('Show shortcuts'),
71
    '#href' => '',
72
    '#options' => array(
73
      'attributes' => array('class' => array('shortcut-toggle')),
74
    ),
75
  );
76

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

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

    
105
  // Alter icon.
106
  if (isset($content['icon'])) {
107
    unset($content['icon']['icon']['#theme']);
108
    $content['icon']['icon']['#title'] = '<span>' . t('Home') . '</span>';
109
    $content['icon']['icon']['#attributes']['class'][] = 'admin-menu-toolbar-category';
110
  }
111

    
112
  // Alter user account link.
113
  if (isset($content['account'])) {
114
    $content['account']['account']['#title'] = t('Hello <strong>@username</strong>', array('@username' => $content['account']['account']['#title']));
115
    $content['account']['account']['#options']['html'] = TRUE;
116
  }
117
}
118