Setting active menu items currently doesn't work. The context is run in context_preprocess_page and the menu active item is set in $vars['main-menu'] but I have a feeling that that is too late - links are probably already rendered.

Comments

febbraro’s picture

Status: Active » Postponed (maintainer needs more info)

Can you describe the exact steps to reproduce the problem?

hook_preprocess_page is exactly where it is supposed to be happening
http://api.drupal.org/api/drupal/includes--theme.inc/function/template_p...

We have a unit test that passes and I have verified that it works as expected. What are you seeing that is different?

meba’s picture

Status: Postponed (maintainer needs more info) » Active

1) Create a menu with some submenu items
2) Create a node in the menu
3) Create a context, activate it, put menu item as a reaction

The menu is in block-system-main-menu, rendered in page.tpl.php using render($page['navigation'])

febbraro’s picture

Status: Active » Postponed (maintainer needs more info)

I'm sorry I still dont quite understand what you are expecting to happen and what is actually happening.

Are you implementing hook_preprocess_page and doing anything? What appears to be missing?

Christopher Camps’s picture

The problem occurs when a menu is rendered in a block.

It works fine when a menu is rendered directly inside page.tpl.php with $main_menu.

To see it fail, add the main menu as a block in Bartik and try to highlight one of the items with a context.

Christopher Camps’s picture

Status: Postponed (maintainer needs more info) » Active
febbraro’s picture

Status: Active » Closed (works as designed)

Turns out that Context can;t really solve this problem easily. It sets active on the menus in Primary or Secondary links, not in any old block. Reason is that the block and menu reactions are separate and they dont know about each other. Any solution I can think of at this point will be a disgusting hack.

rjacobs’s picture

For reference, there is some work on this for Drupal 6 (#835090: Context Reaction: Set menu trail) which attempts to create a new reaction that sets the active menu trail (which themes can also use for styling active menu items).

I'm not too sure how that translates to D7, but there seem to be several advocates to get this kind of a reaction into context in general. I believe it could solve some issues like this (assuming the theme is able to go something with "active-trail" classes).

Ryan