1

I've defined a few routes with hook_menu(), and added these routes to a menu with nesting. This works fine for all static routes, but for any route with a wildcard the 'active-trail' does (understandably) not apply to the menu, and the parent menu item is collapsed. How can I enforce that the parent menu item is open and has 'active-trail' class?

This is the hook_menu() implementation I am using.

function my_module_menu() {
  $items['parent'] = array(
    'title' => t("Parent"),
    'page callback' => 'my_module_parent',
    'access callback' => 'user_is_logged_in',
  );
  $items['parent/child'] = array(
    'title' => t("Child"),
    'page callback' => 'my_module_child',
    'access callback' => 'user_is_logged_in',
  );
  $items['parent/child/%'] = array(
    'title' => t("Child Item"),
    'page callback' => 'my_module_child_item',
    'access callback' => 'user_is_logged_in',
    'page arguments' => array(2)
  );

  return $items;
}

My menu (a custom menu) looks like the following.

  • Home
    • Item 1
    • Item 2
    • Parent
      • Child

So if I go to 'parent/child/123' I want the 'parent' and 'child' menu items to be active and not collapsed.

I've tried the Menu Trail by Path module, but it seems to have no effect.

1

I solved the problem with the Link Trail By Path module. This module add active class for 'parent' and 'child' link.

  • This module add active class for 'parent' and 'child' link. His work with hook_preprocess_link – Ruslan Telyak Oct 12 '17 at 12:18
0

Found I can achieve this with menu_set_active_item('parent/child');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.