I have installed the plugin Menu block and I am very happy with the result, but I’d like to change some classes in the structure.
This is what I get right now:
<div class="content"> <ul class="menu"> <li class="first last expanded"> <a class="active" href="http://example.com">News</a> <ul class="menu"> <li class="first last leaf"> <a class="active" href="http://example.com">Test</a> </li> </ul> </li> </ul> </div>
..and this is what I want:
<div class="content"> <ul id="nav-list"> <li class="first last expanded has-submenu"> <a class="active" href="http://example.com">News</a> <ul class="sub-menu"> <li class="first last leaf"> <a class="active" href="http://example.com">Test</a> </li> </ul> </li> </ul> </div>
So I basically want to..
- ..add/change/remove the
<ul>
‘s class and id attributes (level specific, so not the same for the primary/secondary<ul>
). - ..add a
has-submenu
class to an<li>
if it contains another submenu.
What I’ve tried:
As explained in Menu Block’s documentation, a hook function hook_menu_block_tree_alter()
can be implemented. To start ‘somewhere, I tried implementing this in template.php without any success (but doesn’t even get called):
function THEME_menu_block_tree_alter(&$tree, &$config) { foreach ($tree as $key => &$value) { if ($tree[$key]['link']['access'] && !$tree[$key]['link']['hidden']) { $items[] = $tree[$key]; } } $num_items = count($items); foreach ($items as $i => &$data) { $class = array(); if ($data['link']['has_children']) { $class[] = 'has-submenu'; } $element['#attributes']['class'] = $class; } }
Any help would be much appreciated as I don’t really have deep understanding of how and where to implement this hook function. Also my impression is, that some more detailed documentation is missing for this specific hook function..