0

I'm trying to programmatically build a menu on my site, it works fine on all pages except a search view. This code I'm using is below:

        $config = array('menu_name' => $menu_name, 'level' => 2, 'depth' => 10, 'expanded' => true);
        $menu_tree = menu_build_tree($config);

When I do a var_dump() of $menu_tree it has a content key in the array which has all the menu items, but only if the page is a 'normal' node. If it's the search results view then that array key is empty.

Does anyone have any idea why this is?

I also have two custom functions to change the output of the menu however these don't seem to be called as if I do a var_dump("test") at the start of them it has no affect. The two custom methods are:

THEME_menu_tree__menu_footer_links_1()
THEME_menu_link__menu_footer_links_1()
2
  • Where is the code in your first sample? Commented Jul 30, 2015 at 18:23
  • It is being called in a function called THEME_preprocess_region__branding() which I know isn't a default / core Drupal function but that function is called from THEME_preprocess_region().
    – Neil Nand
    Commented Jul 30, 2015 at 18:39

1 Answer 1

0

I worked it out, turns out the problem is different to what I thought.

Because the search view isn't in the menu structure I need to add different values to the $config array. Firstly I needed to add "parent_mid" so it knew what menu item to use as the root for the menu tree & I needed to change the level to 1 to output the links I wanted. Although 2 was still outputting links, just the wrong ones for what I needed.

If you need to work out what the parent_mid is go to Admin > Structure > Menus > Your Menu & hover over the edit link for the menu item you want to be the root of the menu tree, the ID is in the URL. You can also get it programatically, like I did, using menu_node_get_links().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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