Upgrading to Drupal 7
We've been working on upgrading the DesignHammer website to Drupal 7 for the last few weeks. It's not been a bad process, but one particular issue had been vexing us: how to set the active trail for nodes and pages that don't have menu items.
For example, on the DesignHammer website we have a number of Portfolio nodes without menu items. When viewed, the Portfolio link under Work should have the active trail.
Moving from Drupal 6 to Drupal 7
In Drupal 6, this was accomplished easily with the popular Menu Trails module. Problem is, Menu Trails doesn't have a Drupal 7 port. And to make things more complicated, there is a nasty Drupal core bug related to the active trail issue.
After looking through the code in Menu Block, I found out why. Menu Block has a function
menu_block_fix_custom_menus() that handles setting the Drupal core variable
menu_default_active_menus with information about the active menus on the site. Here's a snippet of the function:
1 2 3 4 5 6
If you are working on a new site build in Drupal 7, you won't have any problems with this. But if, like us, you are upgrading from Drupal 6 to Drupal 7, then your main navigation menus are likely called "primary-links" and "secondary-links". As a result, the second check in the
if statement is going to return false, and then your primary links menu won't get added to the active menus variable.
For example, you could do something like:
$active_menus = array('navigation', 'management', 'user-menu', 'main-menu', 'primary-links'); variable_set('menu_default_active_menus', $active_menus);