Note: I'm moving this here per merlinofchaos after posting it against Views.

Description
The Primary Links active trail gets lost when a nested menu item links to a view + one argument. When the same menu item is linked to the view path without the argument, the active trail is preserved, which is the expected behaviour for both cases.

Steps to reproduce
Add a nested (second-level) menu item to the Primary Links, and map it to a view path + single argument. When the nested menu item is clicked, the parent item is not active.

Example
With the Primary Links configuration below, the Fire Systems menu is not active when clicking Control Panels. In this example, 'content/products/id' is the base view path, and '8' is the argument.

Fire Systems
-- Control Panels <-- linked to "content/products/id/8"
-- Detection

The active trail preserved for the Control Panels link with this configuration:

Fire Systems
-- Control Panels <-- linked to "content/products/id"
-- Detection

Also – manually appending the "/8" to path above preserves the active trail when loaded.

I've disabled the only modules (Menu Trails, Menu Block) that I can imagine affecting this and it makes no difference. Any suggestions would be most welcome.

Comments

damien tournoud’s picture

Title: View + Single Argument Breaks Primary Links Active Trail » _menu_translate() sets $item['href'] to the stored path of the router, not to $_GET['q']
Version: 6.10 » 7.x-dev

The core of the issue is that menu_get_item() returns an item where $item['href'] is not what you would expect it to be.

Given the following menu router definition:

$item['my-path'] = array(
  'title' => 'A page',
  'page callback' => 'xxxx',
  'access arguments' => array('xxxx'),
);

When you access 'my-path/yyyyy', menu_get_item() will return $item['href'] = 'my-path', not the expected 'my-path/yyyyy'. Because of this, all the menu links calculations done in menu_tree_page_data() are done relative to 'my-path', not 'my-path/yyyyy'.

The problem in menu_get_item() is in _menu_translate(), where we set $item['href']:

  $link_map = explode('/', $router_item['path']);
  for ($i = 0; $i < $router_item['number_parts']; $i++) {
    if ($link_map[$i] == '%') {
      $link_map[$i] = $path_map[$i];
    }
  }
  $router_item['href'] = implode('/', $link_map);

We should probably add the optional arguments here... but I don't even understand why we go to all that trouble where implode('/', $path_map). Maybe Karoly or Peter could shed some light on this?

alienzed’s picture

subscribing, this issue needs a fix asap!

pwolanin’s picture

I feel like there is an issue for this already?

cangeceiro’s picture

I am experiencing this issue too, for me it happens in conjunction to using a view with an argument and a hierarchical menu of those arguments. probably also worth noting, i am using d6.

changing

 $router_item['href'] = implode('/', $link_map);

to

 $router_item['href'] = $_GET['q'];

technically resolved this issue for me. But I wouldnt call this a "fix" as much as a bandaid.

damien tournoud’s picture

Status: Active » Closed (duplicate)

It is safe to mark this as a duplicate of #576290: Breadcrumbs don't work for dynamic paths & local tasks.