开发者

Cannot override theme_links() in fusion subtheme

I have setup a subtheme under Fusion and created a template.php file in my subtheme. I have added the following theme overrides and it works perfectly.

function ThemeName_menu_local_tasks() {
    $output = '';
  if ($primary = menu_primary_local_tasks()) {
    $output .= "<div class=\"tabs primary\">\n";
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
    $output .= "</div>\n";
  }
  if ($secondary = menu_secondary_local_tasks()) {
    $output .= "<div class=\"tabs secondary\">\n";
    $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
    $output .= "</div>\n";    
  }
  return $output;
}

function ThemeName_filt开发者_C百科er_tips_more_info () {
    return '';
}

function ThemeName_filter_tips() {
    return '';
}

However, when I try to override theme_links, it doesn't work at all.

function ThemeName_links($links, $attributes = array('class' => 'links')) {
  global $language;
  $output = '';

  if (count($links) > 0) {
    $output = '<div class = "abc"><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()))
           && (empty($link['language']) || $link['language']->language == $language->language)) {
        $class .= ' active';
      }
      $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);
      }
      else if (!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></div>';
  }

  return $output;
}

By the way, I added the following to ThemeName_links() above for testing.

<div class = "abc"> and </div>

I have also cleared Flush all cache using Devel.


Everything you do is correct (I am referring to the way you do theme override) and Fusion theme system also works well. At first, when I try to use Fusion theme, I face the same issue as you. But after I went through the Fusion system, and see how Fusion shows the links (include primary-links, secondary-links), I discovered that inside fusion/fusion_core/page.tpl.php file they call this function theme('grid_block', $primary_links_tree, 'primary-menu') to show the primary-links. This is the function theme written by Fusion. So what you need to do is simple, You can call the default theme links function of Drupal: theme('links', $primary_links) and override your ThemName_links() from there on.

One more thing I'm trying to do now is to override grid_block function. If I find out something interesting, I will post more later.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜