menu-local-action.func.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for bootstrap_menu_local_action().
  5. */
  6. /**
  7. * Returns HTML for a single local action link.
  8. *
  9. * @param array $variables
  10. * An associative array containing:
  11. * - element: A render element containing:
  12. * - #link: A menu link array with 'title', 'href', and 'localized_options'
  13. * keys.
  14. *
  15. * @return string
  16. * The constructed HTML.
  17. *
  18. * @see theme_menu_local_action()
  19. *
  20. * @ingroup theme_functions
  21. */
  22. function bootstrap_menu_local_action($variables) {
  23. $link = $variables['element']['#link'];
  24. $options = isset($link['localized_options']) ? $link['localized_options'] : array();
  25. // If the title is not HTML, sanitize it.
  26. if (empty($options['html'])) {
  27. $link['title'] = check_plain($link['title']);
  28. }
  29. $icon = _bootstrap_iconize_text($link['title']);
  30. // Format the action link.
  31. $output = '';
  32. if (isset($link['href'])) {
  33. // Turn link into a mini-button and colorize based on title.
  34. if ($class = _bootstrap_colorize_text($link['title'])) {
  35. if (!isset($options['attributes']['class'])) {
  36. $options['attributes']['class'] = array();
  37. }
  38. $string = is_string($options['attributes']['class']);
  39. if ($string) {
  40. $options['attributes']['class'] = explode(' ', $options['attributes']['class']);
  41. }
  42. $options['attributes']['class'][] = 'btn';
  43. $options['attributes']['class'][] = 'btn-xs';
  44. $options['attributes']['class'][] = 'btn-' . $class;
  45. if ($string) {
  46. $options['attributes']['class'] = implode(' ', $options['attributes']['class']);
  47. }
  48. }
  49. // Force HTML so we can render any icon that may have been added.
  50. $options['html'] = !empty($options['html']) || !empty($icon) ? TRUE : FALSE;
  51. $output .= l($icon . $link['title'], $link['href'], $options);
  52. }
  53. else {
  54. $output .= $icon . $link['title'];
  55. }
  56. return $output;
  57. }