admin_menu_toolbar.module

  1. nittany7 modules/contrib/admin_menu/admin_menu_toolbar/admin_menu_toolbar.module
  2. cis7 modules/contrib/admin_menu/admin_menu_toolbar/admin_menu_toolbar.module
  3. mooc7 modules/contrib/admin_menu/admin_menu_toolbar/admin_menu_toolbar.module

Renders Administration menu like Toolbar (core) module.

@todo Separate shortcut functionality into own module/widget.

Functions

File

modules/contrib/admin_menu/admin_menu_toolbar/admin_menu_toolbar.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Renders Administration menu like Toolbar (core) module.
  5. *
  6. * @todo Separate shortcut functionality into own module/widget.
  7. */
  8. /**
  9. * Implements hook_form_FORMID_alter().
  10. */
  11. function admin_menu_toolbar_form_admin_menu_theme_settings_alter(&$form) {
  12. // Add the shortcut links as component on behalf of Shortcut module.
  13. $form['plugins']['admin_menu_components']['#options']['shortcut.links'] = t('Shortcuts');
  14. // The shortcut bar consists of two elements, so we target their class names
  15. // instead of cluttering the markup with additional IDs.
  16. $form['plugins']['admin_menu_components']['shortcut.links']['#attributes']['rel'] = '.shortcut-toggle, .shortcut-toolbar';
  17. }
  18. /**
  19. * Implementation of hook_page_build().
  20. */
  21. function admin_menu_toolbar_page_build(&$page) {
  22. if (!isset($page['page_bottom']['admin_menu'])) {
  23. return;
  24. }
  25. $path = drupal_get_path('module', 'admin_menu_toolbar');
  26. $attached = &$page['page_bottom']['admin_menu']['#attached'];
  27. $options = array('every_page' => TRUE);
  28. $attached['css'][$path . '/admin_menu_toolbar.css'] = $options;
  29. $attached['js'][$path . '/admin_menu_toolbar.js'] = $options;
  30. // @todo Stop-gap fix until cached rendering is resolved.
  31. // @see http://drupal.org/node/1567622
  32. if (module_exists('shortcut')) {
  33. $attached['css'][drupal_get_path('module', 'shortcut') . '/shortcut.css'] = $options;
  34. }
  35. $settings = array();
  36. // Add current path to support menu item highlighting.
  37. // @todo Compile real active trail here?
  38. $args = explode('/', $_GET['q']);
  39. if ($args[0] == 'admin' && !empty($args[1])) {
  40. $settings['activeTrail'] = url($args[0] . '/' . $args[1]);
  41. }
  42. elseif (drupal_is_front_page()) {
  43. $settings['activeTrail'] = url('<front>');
  44. }
  45. $attached['js'][] = array(
  46. 'data' => array('admin_menu' => array('toolbar' => $settings)),
  47. 'type' => 'setting',
  48. );
  49. }
  50. /**
  51. * Implements hook_admin_menu_output_build().
  52. */
  53. function admin_menu_toolbar_admin_menu_output_build(&$content) {
  54. if (empty($content['#components']['shortcut.links']) && !$content['#complete']) {
  55. return;
  56. }
  57. // Add shortcuts toggle.
  58. $content['shortcut-toggle'] = array(
  59. '#access' => module_exists('shortcut'),
  60. '#weight' => -200,
  61. '#type' => 'link',
  62. '#title' => t('Show shortcuts'),
  63. '#href' => '',
  64. '#options' => array(
  65. 'attributes' => array('class' => 'shortcut-toggle'),
  66. ),
  67. );
  68. // Add shortcuts bar.
  69. $content['shortcut'] = array(
  70. '#access' => module_exists('shortcut'),
  71. '#weight' => 200,
  72. '#prefix' => '<div class="shortcut-toolbar">',
  73. '#suffix' => '</div>',
  74. );
  75. $content['shortcut']['shortcuts'] = array(
  76. // Shortcut module's CSS relies on Toolbar module's markup.
  77. // @see http://drupal.org/node/1217038
  78. '#prefix' => '<div id="toolbar">',
  79. '#suffix' => '</div>',
  80. // @todo Links may contain .active-trail classes.
  81. '#pre_render' => array('shortcut_toolbar_pre_render'),
  82. );
  83. }
  84. /**
  85. * Implements hook_admin_menu_output_alter().
  86. */
  87. function admin_menu_toolbar_admin_menu_output_alter(&$content) {
  88. // Add a class to top-level items for styling.
  89. if (isset($content['menu'])) {
  90. foreach (element_children($content['menu']) as $link) {
  91. $content['menu'][$link]['#attributes']['class'][] = 'admin-menu-toolbar-category';
  92. }
  93. }
  94. // Alter icon.
  95. if (isset($content['icon'])) {
  96. unset($content['icon']['icon']['#theme']);
  97. $content['icon']['icon']['#title'] = '<span>' . t('Home') . '</span>';
  98. $content['icon']['icon']['#attributes']['class'][] = 'admin-menu-toolbar-category';
  99. }
  100. // Alter user account link.
  101. if (isset($content['account'])) {
  102. $content['account']['account']['#title'] = t('Hello <strong>@username</strong>', array('@username' => $content['account']['account']['#title']));
  103. $content['account']['account']['#options']['html'] = TRUE;
  104. }
  105. }