menu-link.func.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for bootstrap_menu_link() and suggestion(s).
  5. */
  6. /**
  7. * Returns HTML for a menu link and submenu.
  8. *
  9. * @param array $variables
  10. * An associative array containing:
  11. * - element: Structured array data for a menu link.
  12. *
  13. * @return string
  14. * The constructed HTML.
  15. *
  16. * @see theme_menu_link()
  17. *
  18. * @ingroup theme_functions
  19. */
  20. function bootstrap_menu_link(array $variables) {
  21. $element = $variables['element'];
  22. $sub_menu = '';
  23. if ($element['#below']) {
  24. // Prevent dropdown functions from being added to management menu so it
  25. // does not affect the navbar module.
  26. if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) {
  27. $sub_menu = drupal_render($element['#below']);
  28. }
  29. elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
  30. // Add our own wrapper.
  31. unset($element['#below']['#theme_wrappers']);
  32. $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
  33. // Generate as standard dropdown.
  34. $element['#title'] .= ' <span class="caret"></span>';
  35. $element['#attributes']['class'][] = 'dropdown';
  36. $element['#localized_options']['html'] = TRUE;
  37. // Set dropdown trigger element to # to prevent inadvertant page loading
  38. // when a submenu link is clicked.
  39. $element['#localized_options']['attributes']['data-target'] = '#';
  40. $element['#localized_options']['attributes']['class'][] = 'dropdown-toggle';
  41. $element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
  42. }
  43. }
  44. // On primary navigation menu, class 'active' is not set on active menu item.
  45. // @see https://drupal.org/node/1896674
  46. if (($element['#href'] == $_GET['q'] || ($element['#href'] == '<front>' && drupal_is_front_page())) && (empty($element['#localized_options']['language']))) {
  47. $element['#attributes']['class'][] = 'active';
  48. }
  49. $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  50. return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
  51. }
  52. /**
  53. * Overrides theme_menu_link() for book module.
  54. */
  55. function bootstrap_menu_link__book_toc(array $variables) {
  56. $element = $variables['element'];
  57. $sub_menu = drupal_render($element['#below']);
  58. $element['#attributes']['role'] = 'presentation';
  59. $link = TRUE;
  60. if ($element['#title'] && $element['#href'] === FALSE) {
  61. $element['#attributes']['class'][] = 'dropdown-header';
  62. $link = FALSE;
  63. }
  64. elseif ($element['#title'] === FALSE && $element['#href'] === FALSE) {
  65. $element['#attributes']['class'][] = 'divider';
  66. $link = FALSE;
  67. }
  68. elseif (($element['#href'] == $_GET['q'] || ($element['#href'] == '<front>' && drupal_is_front_page())) && (empty($element['#localized_options']['language']))) {
  69. $element['#attributes']['class'][] = 'active';
  70. }
  71. if ($link) {
  72. $element['#title'] = l($element['#title'], $element['#href'], $element['#localized_options']);
  73. }
  74. return '<li' . drupal_attributes($element['#attributes']) . '>' . $element['#title'] . $sub_menu . "</li>\n";
  75. }