If the source for secondary menu is the main menu, then the full main menu gets displayed a second time as secondary menu (instead of second level links from active main menu link).

Comments

markhalliwell’s picture

Status: Active » Closed (duplicate)
Related issues: +#1893532: [bootstrap][policy][7.x-3.x] Navigation/Menus
quimic’s picture

IMHO this is not a duplicate of #1893532. #1893532 is a very global task around menus dynamic behaviour.
This one a specific bug regarding the content of the secondary menu. It is not about styling or behaviours. The actual generated content is wrong.

markhalliwell’s picture

Issue tags: -secondary menu

It is a dup. If there wasn't the legacy cruft of manipulating the menus like that (ie: primary/second variables in $page) and just using normal system, then this really wouldn't be an issue: https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_seco...

dimon4ikzp’s picture

It still doesn't work since 3 years

My Solution:

add function to template.php

function SUBTHEME_links__system_secondary_menu($variables) {
  $links = $variables['links'];
  global $language_url;
  $output = '';

  if (count($links) > 0) {
    // Treat the heading first if it is present to prepend it to the
    // list of links.
    //$output .= '<ul' . drupal_attributes($attributes) . '>';
    $output .= '<ul class="menu nav navbar-nav secondary">';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = array($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_url->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);
      }
      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;
}

and replace "Secondary nav part" in page.vars.php to:

  // Secondary nav.
  $variables['secondary_nav'] = FALSE;
  if ($variables['secondary_menu']) {
    // Build links.

    if (variable_get('menu_secondary_links_source', 'user-menu') == variable_get('menu_main_links_source', 'main-menu')) {
      $variables['secondary_nav'] = theme('links__system_secondary_menu', array(
        'links' => $variables['secondary_menu']
      ));
    }
    else {
      $variables['secondary_nav'] = menu_tree(variable_get('menu_secondary_links_source', 'user-menu'));
    }

    // Provide default theme wrapper function.
    //$variables['secondary_nav']['#theme_wrappers'] = array('menu_tree__secondary');
  }
grabby’s picture

I agree that this is a separate issue and #4 works for me. Any chance of testing / committing?