home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (admin_menu_toolbar.module)

This example Drupal source code file (admin_menu_toolbar.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

args, array, content, function, if, js, path, php, settings, span, string, theme, title, true

The admin_menu_toolbar.module Drupal example source code

<?php
// $Id: admin_menu_toolbar.module,v 1.4 2010/02/19 23:19:00 sun Exp $

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

/**
 * Implementation of hook_init().
 *
 * @todo Add another admin_menu hook to avoid cluttering hook_init().
 */
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', array('preprocess' => FALSE));
  // Performance: Defer execution.
  drupal_add_js($path . '/admin_menu_toolbar.js', array('defer' => 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]);
  }
  elseif (drupal_is_front_page()) {
    $settings['activeTrail'] = url('<front>');
  }
  drupal_add_js(array('admin_menu' => array('toolbar' => $settings)), 'setting');
}

/**
 * Implementation of 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;

  // Add shortcuts menu.
  $content['shortcuts'] = array(
    '#theme' => 'admin_menu_links',
    '#weight' => -200,
  );
  $content['shortcuts']['shortcuts'] = array(
    '#title' => t('Show shortcuts'),
    // @todo How do we want to trigger/store state?
    '#attributes' => array('class' => array('admin-menu-shortcuts')),
    //'#attributes' => array('class' => array('admin-menu-shortcuts', 'admin-menu-shortcuts-active')),
    '#options' => array(
      'attributes' => array('class' => 'toggle'),
    ),
  );
  // @todo *Move* this from $content['menu'] instead.
  $content['shortcuts']['shortcuts']['node-add'] = array(
    '#title' => t('Add content'),
    '#href' => 'node/add',
  );
  $content['shortcuts']['shortcuts']['admin-content-node'] = array(
    '#title' => t('Find content'),
    '#href' => 'admin/content/node',
    '#access' => user_access('administer nodes'),
  );
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal admin_menu_toolbar.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.