adminimal_admin_menu.module 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * @file
  4. * Themes Administration menu like Adminimal theme.
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function adminimal_admin_menu_menu() {
  10. $items = array();
  11. $items['admin/config/administration/adminimal_menu'] = array(
  12. 'title' => 'Adminimal menu',
  13. 'description' => 'Adjust adminimal menu settings.',
  14. 'page callback' => 'drupal_get_form',
  15. 'page arguments' => array('adminimal_admin_menu_settings'),
  16. 'access arguments' => array('administer site configuration'),
  17. 'file' => 'adminimal_menu_settings.inc',
  18. );
  19. return $items;
  20. }
  21. /**
  22. * Implements hook_page_build().
  23. */
  24. function adminimal_admin_menu_page_build(&$page) {
  25. if (!_adminimal_admin_menu_access()) {
  26. return;
  27. }
  28. $path = drupal_get_path('module', 'adminimal_admin_menu');
  29. // Attach the CSS and JavaScript assets.
  30. drupal_add_css($path . '/adminimal_admin_menu.css');
  31. drupal_add_js($path . '/adminimal_admin_menu.js', 'file');
  32. if (!isset($page['page_bottom']['admin_menu'])) {
  33. return;
  34. }
  35. $attached = &$page['page_bottom']['admin_menu']['#attached'];
  36. $options = array('every_page' => TRUE);
  37. // @todo Stop-gap fix until cached rendering is resolved.
  38. // @see http://drupal.org/node/1567622
  39. if (module_exists('shortcut')) {
  40. $attached['css'][drupal_get_path('module', 'shortcut') . '/shortcut.css'] = $options;
  41. }
  42. $settings = array();
  43. // Add current path to support menu item highlighting.
  44. // @todo Compile real active trail here?
  45. $args = explode('/', $_GET['q']);
  46. if ($args[0] == 'admin' && !empty($args[1])) {
  47. $settings['activeTrail'] = url($args[0] . '/' . $args[1]);
  48. }
  49. elseif (drupal_is_front_page()) {
  50. $settings['activeTrail'] = url('<front>');
  51. }
  52. $attached['js'][] = array(
  53. 'data' => array('admin_menu' => array('toolbar' => $settings)),
  54. 'type' => 'setting',
  55. );
  56. }
  57. /**
  58. * Implements hook_admin_menu_output_build().
  59. */
  60. function adminimal_admin_menu_admin_menu_output_build(&$content) {
  61. if (variable_get('adminimal_admin_menu_render', 'collapsed') != 'hidden') {
  62. // Add shortcuts bar.
  63. $content['shortcut'] = array(
  64. '#access' => module_exists('shortcut'),
  65. '#weight' => 200,
  66. '#prefix' => '<div class="shortcut-toolbar">',
  67. '#suffix' => '</div>',
  68. );
  69. $content['shortcut']['shortcuts'] = array(
  70. // Shortcut module's CSS relies on Toolbar module's markup.
  71. // @see http://drupal.org/node/1217038
  72. '#prefix' => '<div id="toolbar">',
  73. '#suffix' => '</div>',
  74. // @todo Links may contain .active-trail classes.
  75. '#pre_render' => array('shortcut_toolbar_pre_render'),
  76. );
  77. }
  78. }
  79. /**
  80. * Implements hook_admin_menu_output_alter().
  81. */
  82. function adminimal_admin_menu_admin_menu_output_alter(&$content) {
  83. // Add a class to top-level items for styling.
  84. foreach (element_children($content['menu']) as $link) {
  85. $content['menu'][$link]['#attributes']['class'][] = 'admin-menu-toolbar-category';
  86. }
  87. // Alter icon.
  88. unset($content['icon']['icon']['#theme']);
  89. $content['icon']['icon']['#title'] = '<span class="admin-menu-home-icon">&nbsp;</span>';
  90. $content['icon']['icon']['#attributes']['class'][] = 'admin-menu-toolbar-home-menu';
  91. $page['#attributes']['class'][] = 'adminimal-menu';
  92. // Hide the menu.
  93. if (variable_get('adminimal_admin_menu_render', 'collapsed') == 'exclusive') {
  94. unset($content['icon']['icon']);
  95. unset($content['search']);
  96. foreach ($content['menu'] as $key => $link) {
  97. // Move local tasks on 'admin' into icon menu.
  98. unset($content['menu'][$key]);
  99. }
  100. }
  101. }
  102. /**
  103. * Implements hook_preprocess_html().
  104. */
  105. function adminimal_admin_menu_preprocess_html(&$vars) {
  106. if (!_adminimal_admin_menu_access()) {
  107. return;
  108. }
  109. // Add the "adminimal" class to the body for better css selection.
  110. $vars['classes_array'][] = 'adminimal-menu';
  111. // Add the shortcut render mode class.
  112. $vars['classes_array'][] = 'menu-render-'.variable_get('adminimal_admin_menu_render', 'collapsed');
  113. }
  114. /**
  115. * Check if the user has access to use the admin menu.
  116. * @return boolean Result of access checks.
  117. */
  118. function _adminimal_admin_menu_access() {
  119. if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) {
  120. return FALSE;
  121. }
  122. // Performance: Skip this entirely for AJAX requests.
  123. if (strpos($_GET['q'], 'js/') === 0) {
  124. return FALSE;
  125. }
  126. return TRUE;
  127. }