theme.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Preprocessor for theme('admin_toolbar').
  4. */
  5. function template_preprocess_admin_toolbar(&$vars) {
  6. // Set the active block.
  7. $active = admin_get_settings('active_tab') ? admin_get_settings('active_tab') : key($vars['blocks']);
  8. if (!empty($vars['blocks'])) {
  9. $blocks = $vars['blocks'];
  10. $vars['tabs'] = array();
  11. $vars['blocks'] = array();
  12. foreach ($blocks as $block) {
  13. $bid = $block->bid;
  14. $vars['tabs'][$bid] = array(
  15. 'title' => $block->subject,
  16. 'attributes' => array('id' => 'admin-tab-' . $bid),
  17. );
  18. $vars['blocks'][$bid] = $block;
  19. // Mark active tab, block.
  20. if ($bid == $active) {
  21. $vars['blocks'][$bid]->class = 'admin-active';
  22. $vars['tabs'][$bid]['active'] = TRUE;
  23. }
  24. }
  25. }
  26. }
  27. /**
  28. * Theme function for form API element '#type' => 'admin_panes'.
  29. */
  30. function template_preprocess_admin_panes(&$vars) {
  31. drupal_add_js(drupal_get_path('module', 'admin') . '/includes/admin.toolbar.js');
  32. $vars['layout'] = admin_get_settings('layout');
  33. $vars['labels'] = $vars['panels'] = $vars['others'] = array();
  34. $first = TRUE;
  35. foreach (element_children($vars['element']) as $key) {
  36. if (!isset($vars['element'][$key]['#access']) || $vars['element'][$key]['#access']) {
  37. if (!empty($vars['element'][$key]['#title'])) {
  38. $vars['labels'][$key] = l($vars['element'][$key]['#title'], $_GET['q'], array(
  39. 'fragment' => 'admin-pane-' . $key,
  40. 'attributes' => array(
  41. 'class' => array($first ? 'admin-pane-active' : '')
  42. )
  43. ));
  44. $vars['panels'][$key] = $vars['element'][$key];
  45. $first = FALSE;
  46. }
  47. else {
  48. $vars['others'][] = $vars['element'][$key];
  49. }
  50. }
  51. }
  52. }
  53. /**
  54. * Generate markup for an admin tab.
  55. */
  56. function theme_admin_tab($variables) {
  57. $tab = $variables['tab'];
  58. $class = $variables['class'];
  59. $attr = isset($tab['attributes']) ? drupal_attributes($tab['attributes']) : '';
  60. $class .= !empty($tab['active']) ? ' admin-tab-active' : '';
  61. $title = filter_xss_admin($tab['title']);
  62. return "<div class='admin-tab {$class}'><span {$attr}>{$title}</span></div>";
  63. }
  64. /**
  65. * Alternative to menu_tree_output() which uses admin implementations of the
  66. * core menu theme functions.
  67. */
  68. function theme_admin_drilldown_menu_tree_output($variables) {
  69. $tree = $variables['menu'];
  70. $output = '';
  71. $items = array();
  72. // Pull out just the menu items we are going to render so that we
  73. // get an accurate count for the first/last classes.
  74. foreach ($tree as $data) {
  75. if (!$data['link']['hidden']) {
  76. $items[] = $data;
  77. }
  78. }
  79. $num_items = count($items);
  80. foreach ($items as $i => $data) {
  81. $extra_class = NULL;
  82. if ($i == 0) {
  83. $extra_class = 'first';
  84. }
  85. if ($i == $num_items - 1) {
  86. $extra_class = 'last';
  87. }
  88. $link = theme('admin_drilldown_menu_item_link', array('item' => $data['link']));
  89. $in_active_trail = isset($data['link']['in_active_trail']) ? $data['link']['in_active_trail'] : FALSE;
  90. if ($data['below']) {
  91. $output .= theme('admin_drilldown_menu_item', array('link' => $link, 'has_children' => $data['link']['has_children'], 'menu' => theme('admin_drilldown_menu_tree_output', array('menu' => $data['below'])), 'in_active_trail' => $in_active_trail, 'extra_class' => $extra_class));
  92. }
  93. else {
  94. $output .= theme('admin_drilldown_menu_item', array('link' => $link, 'has_children' => $data['link']['has_children'], 'menu' => '', 'in_active_trail' => $in_active_trail, 'extra_class' => $extra_class));
  95. }
  96. }
  97. return $output ? theme('admin_drilldown_menu_tree', array('menu' => $output)) : '';
  98. }
  99. /**
  100. * Alternative to theme_menu_tree().
  101. * Ensures custom theme-level overrides of theme_menu_tree() do not break
  102. * markup expected by admin.
  103. */
  104. function theme_admin_drilldown_menu_tree($variables) {
  105. $tree = $variables['menu'];
  106. return theme_menu_tree($tree);
  107. }
  108. /**
  109. * Alternative to theme_menu_item().
  110. * Ensures custom theme-level overrides of theme_menu_item() do not break
  111. * markup expected by admin.
  112. */
  113. function theme_admin_drilldown_menu_item($variables) {
  114. $link = $variables['link'];
  115. $has_children = $variables['has_children'];
  116. $menu = $variables['menu'];
  117. $in_active_trail = $variables['in_active_trail'];
  118. $extra_class = $variables['extra_class'];
  119. return theme_menu_item($link, $has_children, $menu, $in_active_trail, $extra_class);
  120. }
  121. /**
  122. * Alternative to theme_menu_item_link().
  123. */
  124. function theme_admin_drilldown_menu_item_link($variables) {
  125. $link = $variables['item'];
  126. $link['localized_options'] = empty($link['localized_options']) ? array() : $link['localized_options'];
  127. $link['localized_options']['html'] = TRUE;
  128. $link['localized_options']['purl'] = array('disabled' => TRUE);
  129. $link['description'] = check_plain(truncate_utf8(strip_tags($link['description']), 150, TRUE, TRUE));
  130. $link['title'] .= !empty($link['description']) ? "<span class='menu-description'>{$link['description']}</span>" : '';
  131. $link['title'] = filter_xss_admin($link['title']);
  132. return l($link['title'], $link['href'], $link['localized_options']);
  133. }