Welcome to EdReel.com!Recently, I worked on a web site that included the Tree Menus module. This module basically leverages the existing Drupal menu system to allow sub-level menu items in a tree hierarchy. One of the requirements of the project was to create a top-level navigation menu with tabs that worked in sync with a left sidebar menu.
Each tab needed to change colors as it became "active" with the associated content page. This worked great for all top-level content pages but created a problem for sub-level items which needed to maintain focus on the parent tab for the child pages. In other words, the parent tab color needed to remain the same for all child pages.
The module worked great for the left sidebar since each sub-level item was in sync with the associated content page and changed colors for pages in focus. However, the top-level navigation did not keep focus on the parent item. This required logic to maintain "active" status for the parent item on all the sub-level items.
In order to leverage the module to produce the desired effect, I needed to add a theme function to tree_menus.module to keep the top-level menu navs "active" for parent items. In this module was a private function called _tree_menu_tree that included logic for the submenu items as follows:
The $class variable contained the style (eg. color) for "active" list items. Not surprisingly, the name of the class needed was called "active". In order to override the $class variable, I needed to make it theme-able so I could control "active" status. I modified the function to include the code as follows:
I then created a new function called theme_tree_menu_active as shown below:
function theme_tree_menu_active($class, $delta, $level, $index)
{
}
To give you an idea of how this function works, it is necessary to explain what each parameter entails. The $class parameter is the css style class for the list item tag. The $delta parameter is the index of the menu itself (eg. top or sidebar menu). The $level parameter is the index of the menu hierarchy (eg. 1 for top-level parent, 2 for second sub-level child and so on...). Finally, the $index parameter is the index of the actual menu item. Knowing these parameters will determine which menu item is being rendered at any given time.
The last step in the process was to perform the module override in the template.php file for the theme. This was accomplished using the code as follows:
function [name of theme here]_tree_menu_active($class, $delta, $level, $index)
{
}
This code will keep the top-level menu (eg. $delta == 2) item "active" for each sub-level menu item for the second top-level menu tab (eg. $index == 1) and seventh top-level menu tab (eg. $index == 6).
In conclusion, a dependency of this process assumes that the pathauto module is enabled and that all nodes are prefixed with "/content/" in the path alias. You may wish to use the node value of the path instead (eg. /node/13). I hope this article was useful for anyone else having trouble leveraging menus in Drupal. If nothing else, it should provide a good starting point on how to make any module, custom or otherwise, more theme-able.