summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.18/sites/all/modules/admin_menu/admin_menu_toolbar/admin_menu_toolbar.module
blob: 1885fcef26ee0ccd69ab55a60e2ad5044e6e2669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php

/**
 * @file
 * Renders Administration menu like Toolbar (core) module.
 *
 * @todo Separate shortcut functionality into own module/widget.
 */

/**
 * Implementation of hook_page_build().
 */
function admin_menu_toolbar_page_build(&$page) {
  if (!isset($page['page_bottom']['admin_menu'])) {
    return;
  }
  $path = drupal_get_path('module', 'admin_menu_toolbar');
  $attached = &$page['page_bottom']['admin_menu']['#attached'];
  $options = array('every_page' => TRUE);

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

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

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

  $attached['js'][] = array(
    'data' => array('admin_menu' => array('toolbar' => $settings)),
    'type' => 'setting',
  );
}

/**
 * Implements hook_admin_menu_output_build().
 */
function admin_menu_toolbar_admin_menu_output_build(&$content) {
  // Add shortcuts toggle.
  $content['shortcut-toggle'] = array(
    '#access' => module_exists('shortcut'),
    '#weight' => -200,
    '#type' => 'link',
    '#title' => t('Show shortcuts'),
    '#href' => '',
    '#options' => array(
      'attributes' => array('class' => 'shortcut-toggle'),
    ),
  );

  // Add shortcuts bar.
  $content['shortcut'] = array(
    '#access' => module_exists('shortcut'),
    '#weight' => 200,
    '#prefix' => '<div class="shortcut-toolbar">',
    '#suffix' => '</div>',
  );
  $content['shortcut']['shortcuts'] = array(
    // Shortcut module's CSS relies on Toolbar module's markup.
    // @see http://drupal.org/node/1217038
    '#prefix' => '<div id="toolbar">',
    '#suffix' => '</div>',
    // @todo Links may contain .active-trail classes.
    '#pre_render' => array('shortcut_toolbar_pre_render'),
  );
}

/**
 * Implements hook_admin_menu_output_alter().
 */
function admin_menu_toolbar_admin_menu_output_alter(&$content) {
  // Add a class to top-level items for styling.
  foreach (element_children($content['menu']) as $link) {
    $content['menu'][$link]['#attributes']['class'][] = 'admin-menu-toolbar-category';
  }

  // Alter icon.
  unset($content['icon']['icon']['#theme']);
  $content['icon']['icon']['#title'] = '<span>' . t('Home') . '</span>';
  $content['icon']['icon']['#attributes']['class'][] = 'admin-menu-toolbar-category';

  // Alter user account link.
  $content['user']['account']['#title'] = t('Hello <strong>@username</strong>', array('@username' => $content['user']['account']['#title']));
  $content['user']['account']['#options']['html'] = TRUE;
}