This document is intended for module developers who wish to make use of JQuery to process an array of hierarchical data into a click and expand menu. It is written with the assumption that you are a programmer and that you know how to create multidimensional arrays through recursive functions.
The only function that third party modules need to call from JQuery menu in order to create a click and expand menu is as follows:theme(‘menu_creation_by_array’, $menutree, $trail);
This calls the theme function menu_creation_by_array() and sends it two arguments:
$menutree : $menutree is a multidimensional array of containing the information necessary to create links. It is formatted in the same pattern as the tree that you get from calling menu_tree_all_data(). For reference I recommend calling menu_tree_all_data(‘navigation’) and using the var_dump function to look at the structure. I copied and pasted this dump to a text file in order to refer to it as I was writing the JQuery Menu module. JQuery Menu does not need all of the elements provided by the menu_tree_all_data() function. Below is a list of the elements that are used by JQuery Menu:
$item[‘link’][‘href’] : The actual path to be linked to. It is best to use pre-alias paths such as node/1 etc… as the paths will automatically be converted at run time.
$item[‘link’][‘title’] : The text to be displayed in the link.
$item[‘link’][‘has_children’] : set to 1 or 0, this determines if the link will have a clickable plus or minus sign in the case of 1 or a normal list bullet in the case of 0.
$item[‘link’][‘expanded’] : set to 1 or 0, this determines if the link should be expanded by default.
$item[‘link’][‘options’][‘attributes’] : Any attributes such as classes that you want to pass as the $options array to the l() function can be set here. You should read up on the l() function at api.Drupal.org for more information http://api.drupal.org/api/function/l/6.
$item[‘link’][‘hidden’] : If you want your item to remain in the tree but not to be displayed you can set hidden to 1 here.
Subsequent levels of the menu are created by generating the same structure from $item[‘below’]. So for a second level menu href it would look as follows: $item[‘below’] [‘link’][‘href’]. The best way to create such an array is to develop the logic in such a way that you can run the function recursively on itself as many times as needed to transverse all levels of the array you are creating. For examples of this you can look at the source code for the Advanced Taxonomy Blocks module.
$trail: The $trail argument for the theme(‘menu_creation_by_array’, $menutree, $trail); function is a simple indexed array of paths that are used to generate the active trail. For a typical menu this array is generated with menu_get_active_trail(). However is some situations as is the case for the Advanced Taxonomy Blocks module the active trail needed is not based on the menu but rather on the taxonomy hierarchy. Your module can implement the active trail based on the current page however it wants. JQuery menu will check the $trail array against all of the links in the hierarch and apply set those elements to be expanded. For an example of a simple trail array… say you are visiting a taxonomy page for term 3 who’s parent is term 2. If term 2 is a top level term then the trail might be as follows:$trail = array(
You can decide how you implement the active trail but the best idea is to have the trail match the hierarchy of the menu so that the menu will open appropriately.
Drupal Module Development Advanced Drupal Tutorials Module Documentation
- Jquery Menu Module
- Advanced Book Blocks
- Advanced Taxonomy Blocks
- Consistent Language Interface
Stay informed on our latest news!Email: * Previous issues
Drupal Tutorals RSS
How to Declare a Views Template Inside of a Module
How to Remove all SVN Folders from a Site
Svn has an annoying habit of adding thousands of folders and files into every level of your site when you put your code under…[Read More]
How to turn off Vertical Tabs for a specific content type
I rarely do any heavy structural changes to node edit pages, so until today I hadn’t ever had a reason to disable vertical tabs…[Read More] Drupal Tutorials Drupal Blog RSS
Free, Unlimited, Private Git Hosting – The Holy Grail of Version Control
If I were paid minimum wage for the time I have spent investigating various git and svn hosting services (both free and paid) I…[Read More]
Mac OSX + Drush = Time saved
The longer I have my mac the more things I find that drastically simplify my life as a Drupal developer. Now for fairness sake I…[Read More]
New to Drupal? A word from the wise: Never say newbie!
I have nothing against new Drupal users on Drupal.org, even the most advanced Drupal developers were new to Drupal at one point…[Read More] Drupal Blog
- Refund Policy
- Business Ethics
- View Drupal.org profile
- Follow us on Twitter
- Subscribe through RSS