You are here

function admin_menu_toolbar_init in Administration menu 6.3

Implementation of hook_init().

@todo Add another admin_menu hook to avoid cluttering hook_init().

File

admin_menu_toolbar/admin_menu_toolbar.module, line 15
Renders Administration menu like Toolbar (core) module.

Code

function admin_menu_toolbar_init() {
  if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
    return;
  }

  // Performance: Skip this entirely for AJAX requests.
  if (strpos($_GET['q'], 'js/') === 0) {
    return;
  }
  $path = drupal_get_path('module', 'admin_menu_toolbar');
  drupal_add_css($path . '/admin_menu_toolbar.css', 'module', 'all', FALSE);

  // Performance: Defer execution.
  drupal_add_js($path . '/admin_menu_toolbar.js', 'module', 'header', TRUE);
  $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]);
  }
  drupal_add_js(array(
    'admin_menu' => array(
      'toolbar' => $settings,
    ),
  ), 'setting');
}