Closed (works as designed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
menu system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
16 Aug 2009 at 19:04 UTC
Updated:
29 Jul 2014 at 18:25 UTC
The main menu is giving individual <li> items unique classes, which should be unique IDs.
E.g.:
<ul class="links main-menu">
<li class="menu-138 first">
</li>
<li class="menu-148 last">
</li>
</ul>That should be:
<ul class="links main-menu">
<li id="menu-138 first">
</li>
<li id="menu-148 last">
</li>
</ul>Arguably, "first" and "last" could be retained as classes, since there might be more universal application for those designations. This makes the desired markup as follows:
<ul class="links main-menu">
<li id="menu-138" class="first">
</li>
<li id="menu-148" class="last">
</li>
</ul>I have checked this against Stark, so this seems to be coming out of core, not generated within the theme. (Double-checked against Garland to make sure.) If someone could point me to where this code resides, I will happily roll a patch. Thanks!
(Technically this is a theming issue, but as the code is generated from the menu system, I am guessing the markup is created there. Bad guess?)
Comments
Comment #1
laura s commentedAnd now that I look at it, the
<ul>also has improper tagging. It really should be this:Comment #2
laura s commentedI take back #1 - that is specific to Garland only. Only the li items are relevant here. My apologies.
Comment #3
taslett commentedHi laura s,
I agree that this should be handled on a theme level. Adding unique id's or classes for the li is not necessary for most themes, and if it is necessary can be added by the theme.
Line 1433 of includes/menu.inc ads the class.
$links['menu-' . $item['link']['mlid'] . $class] = $l;I don't see an easy way to make it an id instead.
Comment #4
alexanderpas commentedno, the assumption you make is incorrect:
a menu CAN be displayed (under certain conditions) multiple times on a single page (for example the primary/secondary links block, and the implementation in the theme).
also note that an item can only have a single id, yet multiple classes.
you might wan't to look into theme_menu_item() and theme_menu_tree
for example, sites might be configured in such wat that the theme primary links are also the first level of the site menu.
Comment #5
laura s commentedSorry, but I don't get how
<li class="menu-138 first">makes sense. What is "menu-138" but a unique identifier -- an ID?Comment #6
laura s commentedI am not talking about a menu, I am talking about a menu item with a unique identifier. Sure, you could stretch the meaning and say *anything* could be a class, but that's not how markup was intended, is it?
Comment #7
casey commentedWe should re-discus this in D8 when we (possibly, hopefully) are dropping support for IE6 so we can use attribute selectors and drop those classes too.
.menu > li > a[href=...]Anyway I am pretty sure this isn't going to change in D7.
Comment #8
mtyf commentedLooking for the same implementation of IDs for theming with sprites;
There is a buggy way to get ID's in menu:
theme.inc
@1200
further @1215
This does add an ID to each menu item in the form of menu-xxx, but the first item also gets 'active-trail' added to the ID, which should still be a class.
Comment #9
alexanderpas commentedmenu-item-138 is not an unique identifier for a menu item when a menu is displayed multiple times on a page (Remember: a menu contains menu items; If a menu is displayed twice, it's menu items are also. If menu items are displayed twice, an id CANNOT be used).
An example of this displaying twice can be found right here on drupal.org with the menu on the top, and the menu on the bottom.
@mytf: please create a new support request for your issue, and please do not hijack another issue.