Advertisement
asanchez75

Drupal/theming

May 27th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. function cana_menu_item_link($link) {
  2. if (empty($link['localized_options'])) {
  3. $link['localized_options'] = array();
  4. }
  5. if (empty($link['localized_options']['attributes'])) {
  6. $link['localized_options']['attributes'] = array();
  7. }
  8. $link['localized_options']['attributes'] += array('class' => $link['title']);
  9. return l($link['title'], $link['href'], $link['localized_options']);
  10. }
  11. ================================================================================
  12. function cana_links($variables) {
  13. $links = $variables['links'];
  14. $attributes = $variables['attributes'];
  15. $heading = $variables['heading'];
  16. global $language_url;
  17. $output = '';
  18.  
  19. if (count($links) > 0) {
  20. $output = '';
  21.  
  22. // Treat the heading first if it is present to prepend it to the
  23. // list of links.
  24. if (!empty($heading)) {
  25. if (is_string($heading)) {
  26. // Prepare the array that will be used when the passed heading
  27. // is a string.
  28. $heading = array(
  29. 'text' => $heading,
  30. // Set the default level of the heading.
  31. 'level' => 'h2',
  32. );
  33. }
  34. $output .= '<' . $heading['level'];
  35. if (!empty($heading['class'])) {
  36. $output .= drupal_attributes(array('class' => $heading['class']));
  37. }
  38. $output .= '>' . check_plain($heading['text']) . '</' . $heading['level'] . '>';
  39. }
  40.  
  41. $output .= '<ul' . drupal_attributes($attributes) . '>';
  42.  
  43. $num_links = count($links);
  44. $i = 1;
  45.  
  46. foreach ($links as $key => $link) {
  47. $class = array($key);
  48.  
  49. // Add first, last and active classes to the list of links to help out themers.
  50. $class[] = strtolower($link['title']);
  51. if ($i == 1) {
  52. $class[] = 'first';
  53. }
  54. if ($i == $num_links) {
  55. $class[] = 'last';
  56. }
  57. if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
  58. && (empty($link['language']) || $link['language']->language == $language_url->language)) {
  59. $class[] = 'active';
  60. }
  61. $output .= '<li' . drupal_attributes(array('class' => $class)) . '>';
  62.  
  63. if (isset($link['href'])) {
  64. // Pass in $link as $options, they share the same keys.
  65. $output .= l($link['title'], $link['href'], $link);
  66. }
  67. elseif (!empty($link['title'])) {
  68. // Some links are actually not links, but we wrap these in <span> for adding title and class attributes.
  69. if (empty($link['html'])) {
  70. $link['title'] = check_plain($link['title']);
  71. }
  72. $span_attributes = '';
  73. if (isset($link['attributes'])) {
  74. $span_attributes = drupal_attributes($link['attributes']);
  75. }
  76. $output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';
  77. }
  78.  
  79. $i++;
  80. $output .= "</li>\n";
  81. }
  82.  
  83. $output .= '</ul>';
  84. }
  85.  
  86. return $output;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement