I checked all the bugs reported with related issues like:
- #942782: Custom menus never receive an active trail
- #1579860: No active-trail for menu items for each level greater than 2
- #1578832: [already commited but followup for CR?] <front> menu links are missing active trail classes
All the bugs is reporting that some un-expected results from the menu happens with the active and active-trail classes that must be added to the markup when the current menu link is active.
I tested all the proposed patches their and nothing fixed my bug. Firstly I was using an custom menu block generated from the menu system with no custom modules and I can't see both the active or active trail in the markup. I tried to patch it from #94278 and it didn't work with me.
So, I decided to use primary links or primary menu instead to see the active and active-trail in the markup, In my template I printed the following:
<?php if ($main_menu): ?>
<div id="main-menu" class="navigation">
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu-links',
'class' => array('links', 'menu', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
</div> <!-- /#main-menu -->
<?php endif; ?>
In the theme.info file I added:
features[] = main_menu
In template.php I added the following to add the child-menues to the menu array:
function themeName_links($variables) {
if (array_key_exists('id', $variables['attributes']) && $variables['attributes']['id'] == 'main-menu-links') {
$pid = variable_get('menu_main_links_source', 'main-menu');
$tree = menu_tree($pid);
return drupal_render($tree);
}
return theme_links($variables);
}Everything is working and the menu appears with the child menues, But I can't find the active or active-trail classes in any link in the menu.
I only use Special menu items custom module to be able to make some links without urls in the menu. Disabling this module didn't help too.
Direct link to the site Human Nature Blog the menu on the left sidebar is the primary menu.
I am ready to help and provide any further information.
Comments
Comment #0.0
JonathanHindi commentedfixing related bugs links
Comment #1
tim.plunkettI can't reproduce this in D7 or D8.
I added a View to the main menu in Bartik, and it properly received an active class.
Comment #2
JonathanHindi commentedI am trying to reproduce it on another site but I can't, Any suggestion why I am not receiving an active class on this site. I know I have to open a new issue or support request but if you can give me any guidelines I will be thankful.
Comment #3
tim.plunkettNo need, this can be repurposed.
Comment #4
pasqualleAdding primary links as you did (in you first code snippet), and as core themes do, will display the active class correctly.
I don't not really understand why are you trying themeName_links(), but there is one problem with this code
This will not add active class to menu items.
The replacement would be:
But I would recommend using the https://drupal.org/project/menu_block module if you have special menu requirements.
Comment #4.0
pasquallefixing the first bug link