You are here

function phptemplate_links in Power Menu 6

Same name and namespace in other branches
  1. 7 power_menu.module \phptemplate_links()

Return a themed set of links.

The important difference is that we use the in_active_trail bit here to set an "active" CSS class, which is what most themes (e.g. garland) use to denote an active/open menu item. You should alter/override this as your design needs dictate.

Parameters

$links: A keyed array of links to be themed.

$attributes: A keyed array of attributes

Return value

A string containing an unordered list of links.

File

./power_menu.module, line 439
This module provides some additional menu features. The features are not actually new, but are part of other modules. it's though very cumbersome to creating a new menu item, because one has to go to all the different places to configure these…

Code

function phptemplate_links($links, $attributes = array(
  'class' => 'links',
)) {
  global $language;
  $output = '';
  if (count($links) > 0) {
    $output = '<ul' . drupal_attributes($attributes) . '>';

    //dsm($links);
    $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()) && (empty($link['language']) || $link['language']->language == $language->language)) {
        $class .= ' active';
      }
      $a = '';
      if (isset($link['href'])) {

        // Add active class for containing <li> and <a> if 'active-trail' is set
        // on the link itself.
        if (isset($link['attributes']['class']) && strpos($link['attributes']['class'], 'active-trail') !== FALSE && strpos($class, 'active') === FALSE) {
          $class .= ' active';
          $link['attributes']['class'] .= ' active';
        }

        // Pass in $link as $options, they share the same keys.
        $a = 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']);
        }
        $a = '<span' . $span_attributes . '>' . $link['title'] . '</span>';
      }
      $i++;
      $output .= '<li' . drupal_attributes(array(
        'class' => $class,
      )) . '>';
      $output .= $a;
      $output .= "</li>\n";
    }
    $output .= '</ul>';
  }
  return $output;
}