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.

Comments

cdale’s picture

Status: Active » Needs review
StatusFileSize
new1.7 KB
new1.7 KB

Here'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.

Rowanw’s picture

Here'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 mlid class and change both the li and the a to highlight an individual menu item.

ul.menu li {
  background-image: url(left.png);
}

ul.menu li a {
  background-image: url(right.png);
}

ul.menu li.mlid-6 {
  background-image: url(left-red.png);
}

ul.menu li.mlid-6 a {
  background-image: url(right-red.png);
}
Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

andres_de’s picture

Title: Menu item info in theme_menu_item » missing blank in patch

At 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.

asimmonds’s picture

Title: missing blank in patch » Menu item info in theme_menu_item

Reverting title

jeffschuler’s picture

Status: Needs work » Needs review
StatusFileSize
new1.88 KB

Re-rolled D7 patch to keep up with HEAD.

Some related discussion here: Help customizing theme_menu_item for a single menu.

Status: Needs review » Needs work

The last submitted patch failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.