Fix for Wrap links in span tags

  1. function THEMENAME_links($links, $attributes = array('class' => 'links')) {
  2.   global $language;
  3.   $output = '';
  4.   if (isset($attributes['add_span'])) {
  5.     $span_class = $attributes['add_span'];
  6.     unset($attributes['add_span']);
  7.     $add_span = TRUE;
  8.   }
  9.  
  10.   if (count($links) > 0) {
  11.     $output = '<ul'. drupal_attributes($attributes) .'>';
  12.  
  13.     $num_links = count($links);
  14.     $i = 1;
  15.  
  16.     foreach ($links as $key => $link) {
  17.       $class = $key;
  18.  
  19.       // Add first, last and active classes to the list of links to help out themers.
  20.       if ($i == 1) {
  21.         $class .= ' first';
  22.       }
  23.       if ($i == $num_links) {
  24.         $class .= ' last';
  25.       }
  26.       if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
  27.           && (empty($link['language']) || $link['language']->language == $language->language)) {
  28.         $class .= ' active';
  29.       }
  30.       $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
  31.  
  32.       if (isset($link['href'])) {
  33.         // Pass in $link as $options, they share the same keys.
  34.         if ($add_span) {
  35.           $link['html'] = TRUE;
  36.           $output .= l('<span class="' . $span_class . '">' . $link['title'] . '</span>', $link['href'], $link);
  37.         }
  38.         else {
  39.           $output .= l($link['title'], $link['href'], $link);
  40.         }
  41.       }
  42.       else if (!empty($link['title'])) {
  43.         // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
  44.         if (empty($link['html'])) {
  45.           $link['title'] = check_plain($link['title']);
  46.         }
  47.         $span_attributes = '';
  48.         if (isset($link['attributes'])) {
  49.           $span_attributes = drupal_attributes($link['attributes']);
  50.         }
  51.         $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
  52.       }
  53.  
  54.       $i++;
  55.       $output .= "</li>\n";
  56.     }
  57.  
  58.     $output .= '</ul>';
  59.   }
  60.  
  61.   return $output;
  62. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.