You are here

function custom_breadcrumbs_override_links in Custom Breadcrumbs 7.2

Same name and namespace in other branches
  1. 6.2 custom_breadcrumbs.module \custom_breadcrumbs_override_links()

Override Links.

@todo Please document this function.

See also

http://drupal.org/node/1354

1 string reference to 'custom_breadcrumbs_override_links'
custom_breadcrumbs_theme_registry_alter in ./custom_breadcrumbs.module
Implements hook_theme_registry_alter().

File

./custom_breadcrumbs.module, line 985
Main file for the Custom breadcrumbs.

Code

function custom_breadcrumbs_override_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 = $key;

      // Add first, last and active classes to the list of links to help out
      // themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || $link['href'] == '<front>' && drupal_is_front_page())) {
        $class .= ' active';
      }
      if (custom_breadcrumbs_in_active_trail($link) && $link['href'] != '<front>') {
        $class .= ' active-trail';
      }
      $output .= '<li' . drupal_attributes(array(
        'class' => $class,
      )) . '>';
      if (isset($link['href'])) {

        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);
      }
      elseif (!empty($link['title'])) {

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