Currently it seems as though theme_menu_item's arguments are very stingy in terms of what information it tells you.
It seems to give you the least amount of information possible to achieve a menu item.
In Drupal 5 you were passed the $mid (menu id) which you could use to load information about the menu to make decisions about how to render the items.
This information is most important to me:
mlid = menu link ID (currently you give this to theme_menu_item_link but not to theme_menu_item) I use this to put a class on my list-item because I need to target a particular menu item (not just the link inside the item - this is to achieve clever CSS effects), and the name of the menu item changes, so I cannot use the name of the menu item as a reliable class.
weight - this is useful for creating menu items that need to be z-indexed in CSS in a certain order - see the main menu on this site for an example.
Frankly the whole $link array passed to theme_menu_item_link should be given also to theme_menu_item (not just the link as a string)
Please consider doing this!
Currently I achieve this with a static variable in a setter/getter function to pass this info between the two functions.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 323494-D7_2.diff | 1.88 KB | jeffschuler |
| #1 | menu-item-323494-1-D7.patch | 1.7 KB | cdale |
| #1 | menu-item-323494-1-D6.patch | 1.7 KB | cdale |
Comments
Comment #1
cdale commentedHere's a patch for D6 & 7. I personally consider this to be a bug, as it makes theming menu links harder not to have this information. I pass the whole link array as this allows themers to utilize other information, such as the title.
Comment #2
Rowanw commentedHere's a simple example to demonstrate one of the patch's benefits:
The following CSS would apply two background images to each menu item to give a rounded tab-like appearance, you could then target a single menu item with the
mlidclass and change both theliand theato highlight an individual menu item.Comment #3
Anonymous (not verified) commentedThe last submitted patch failed testing.
Comment #4
andres_de commentedAt least in menu-item-323494-1-D6.patch and as far as I could see also in menu-item-323494-1-D7.patch there is a simple blank missing:
instead of
$class .= 'mlid-'. $data['mlid'];
it should be:
$class .= ' mlid-'. $data['mlid'];
otherwise the classes are not separated properly.
Comment #5
asimmonds commentedReverting title
Comment #6
jeffschulerRe-rolled D7 patch to keep up with HEAD.
Some related discussion here: Help customizing theme_menu_item for a single menu.