menu.inc

  1. cis7 includes/menu.inc
  2. cis7 sites/all/themes/local_contrib/zurb-foundation/inc/menu.inc
  3. cis7 sites/all/modules/ulmus/ctools/includes/menu.inc
  4. cle7 sites/all/themes/local_contrib/zurb_foundation/inc/menu.inc
  5. cle7 sites/all/themes/local_contrib/zurb_foundation/inc/menu.inc
  6. cle7 includes/menu.inc
  7. cle7 sites/all/themes/local_contrib/bootstrap/includes/menu.inc
  8. cle7 sites/all/modules/ulmus/ctools/includes/menu.inc
  9. ecd7 sites/all/themes/local_contrib/zurb_foundation/inc/menu.inc
  10. ecd7 sites/all/modules/ulmus/ctools/includes/menu.inc
  11. ecd7 includes/menu.inc
  12. elmsmedia7 sites/all/themes/local_contrib/zurb_foundation/inc/menu.inc
  13. elmsmedia7 sites/all/modules/ulmus/ctools/includes/menu.inc
  14. elmsmedia7 includes/menu.inc
  15. harmony7 sites/all/modules/ulmus/ctools/includes/menu.inc
  16. harmony7 sites/all/themes/local_contrib/zurb_foundation/inc/menu.inc
  17. harmony7 includes/menu.inc
  18. icor7 sites/all/themes/local_contrib/zurb_foundation/inc/menu.inc
  19. icor7 sites/all/modules/ulmus/ctools/includes/menu.inc
  20. icor7 includes/menu.inc
  21. meedjum_blog7 includes/menu.inc
  22. meedjum_blog7 sites/all/modules/ulmus/ctools/includes/menu.inc
  23. meedjum_blog7 sites/all/themes/local_contrib/zurb_foundation/inc/menu.inc
  24. mooc7 sites/all/themes/local_contrib/zurb_foundation/inc/menu.inc
  25. mooc7 includes/menu.inc
  26. mooc7 sites/all/modules/ulmus/ctools/includes/menu.inc

General menu helper functions.

Functions

Namesort descending Description
ctools_menu_add_tab Dynamically add a tab to the current path.
ctools_menu_sort Re-sort menu items after we have modified them.
_ctools_menu_add_dynamic_items

File

sites/all/modules/ulmus/ctools/includes/menu.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * General menu helper functions.
  5. */
  6. /**
  7. * Dynamically add a tab to the current path.
  8. *
  9. * This function is a simplified interface for adding tabs to the current path.
  10. * Some considerations when doing this:
  11. *
  12. * - First, if there is only 1 tab, Drupal will not show it. Therefore, if
  13. * you are only adding one tab, you should find a way to make sure there is
  14. * already tab, or instead add 2.
  15. * - Second, the caller is responsible for providing access control to these
  16. * links.
  17. *
  18. * @param $link
  19. * An array describing this link. It must contain:
  20. * - 'title': The printed title of the link.
  21. * - 'href': The path of the link. This is an argument to l() so it has all
  22. * of those features and limitations.
  23. * - 'options': Any options that go to l, including query, fragment and html
  24. * options necessary.
  25. * - 'weight': The weight to use in ordering the tabs.
  26. * - 'type': Optional. If set to MENU_DEFAULT_LOCAL_TASK this can be used to
  27. * add a fake 'default' local task, which is useful if you have to add
  28. * tabs to a page that has none.
  29. */
  30. function ctools_menu_add_tab($link = NULL) {
  31. $links = &drupal_static(__FUNCTION__, array());
  32. if (isset($link)) {
  33. $links[$link['href']] = $link;
  34. }
  35. return $links;
  36. }
  37. /**
  38. * Re-sort menu items after we have modified them.
  39. */
  40. function ctools_menu_sort($a, $b) {
  41. $a_weight = (is_array($a) && isset($a['#link']['weight'])) ? $a['#link']['weight'] : 0;
  42. $b_weight = (is_array($b) && isset($b['#link']['weight'])) ? $b['#link']['weight'] : 0;
  43. if ($a_weight == $b_weight) {
  44. $a_title = (is_array($a) && isset($a['#link']['title'])) ? $a['#link']['title'] : 0;
  45. $b_title = (is_array($b) && isset($b['#link']['title'])) ? $b['#link']['title'] : 0;
  46. if ($a_title == $b_title) {
  47. return 0;
  48. }
  49. return ($a_title < $b_title) ? -1 : 1;
  50. }
  51. return ($a_weight < $b_weight) ? -1 : 1;
  52. }
  53. function _ctools_menu_add_dynamic_items(&$data, &$router_item, &$root_path) {
  54. if ($additions = ctools_menu_add_tab()) {
  55. // If none of the static local tasks are active allow one of the dynamic
  56. // active tasks to be marked as such.
  57. $has_active = FALSE;
  58. if (!empty($data['tabs'][0]['output'])) {
  59. foreach ($data['tabs'][0]['output'] as $element) {
  60. if (!empty($element['#link']['#active'])) {
  61. $has_active = TRUE;
  62. }
  63. }
  64. }
  65. foreach ($additions as $addition) {
  66. $addition['localized_options'] = isset($addition['options']) ? $addition['options'] : array();
  67. if (isset($addition['type']) && $addition['type'] == MENU_LOCAL_ACTION) {
  68. $data['actions']['output'][] = array(
  69. '#theme' => 'menu_local_action',
  70. '#link' => $addition,
  71. );
  72. }
  73. else {
  74. $data['tabs'][0]['output'][] = array(
  75. '#theme' => 'menu_local_task',
  76. '#link' => $addition,
  77. '#active' => (!$has_active && $root_path === $addition['href']),
  78. );
  79. }
  80. }
  81. if (!empty($data['tabs'][0]['output'])) {
  82. uasort($data['tabs'][0]['output'], 'ctools_menu_sort');
  83. $data['tabs'][0]['count'] = count($data['tabs'][0]['output']);
  84. }
  85. if (!empty($data['actions']['output'])) {
  86. uasort($data['actions']['output'], 'ctools_menu_sort');
  87. $data['actions']['count'] = count($data['actions']['output']);
  88. }
  89. }
  90. }