You are here

function theme_context_links in Context 5

Same name and namespace in other branches
  1. 6 context.core.inc \theme_context_links()
  2. 6.2 context.core.inc \theme_context_links()

Like theme_links, but handles context warping. theme_links couldn't believe it.

File

context_prefix/context_prefix.module, line 697

Code

function theme_context_links($links, $attributes = array(
  'class' => 'links',
)) {
  $output = '';
  if (count($links) > 0) {
    $output = '<ul' . drupal_attributes($attributes) . '>';
    $num_links = count($links);
    $i = 1;
    foreach ($links as $key => $link) {
      $class = '';

      // Automatically add a class to each link and also to each LI
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
        $class = $key;
      }
      else {
        $link['attributes']['class'] = $key;
        $class = $key;
      }

      // Add active class for active menu items
      if (stristr($key, 'active')) {
        $class .= " active";
      }

      // Add first and last classes to the list of links to help out themers.
      $extra_class = '';
      if ($i == 1) {
        $extra_class .= 'first ';
      }
      if ($i == $num_links) {
        $extra_class .= 'last ';
      }
      $output .= '<li class="' . $extra_class . $class . '">';

      // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;
      if (isset($link['href'])) {
        if ($link['warp']) {
          $output .= cl($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html, TRUE);
        }
        else {
          $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
        }
      }
      else {
        if ($link['title']) {

          //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
          if (!$html) {
            $link['title'] = check_plain($link['title']);
          }
          $output .= '<span' . drupal_attributes($link['attributes']) . '>' . $link['title'] . '</span>';
        }
      }
      $i++;
      $output .= "</li>\n";
    }
    $output .= '</ul>';
  }
  return $output;
}