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

laura s’s picture

And now that I look at it, the <ul> also has improper tagging. It really should be this:

<ul class="links" id"main-menu">
<li id="menu-138" class="first">
</li>
<li id="menu-148" class="last">
</li>
</ul>
laura s’s picture

I take back #1 - that is specific to Garland only. Only the li items are relevant here. My apologies.

taslett’s picture

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

alexanderpas’s picture

Status: Active » Closed (works as designed)

no, 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.

laura s’s picture

Sorry, but I don't get how <li class="menu-138 first"> makes sense. What is "menu-138" but a unique identifier -- an ID?

laura s’s picture

Status: Closed (works as designed) » Active

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

I 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?

casey’s picture

Version: 6.19 » 8.x-dev
Category: feature » bug
Status: Needs review » Closed (works as designed)
Issue tags: -theme, -menu links, -theming links, -theme.inc

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

mtyf’s picture

Version: 7.x-dev » 6.19
Category: bug » feature
Status: Active » Needs review
Issue tags: +theme, +menu links, +theming links, +theme.inc

Looking for the same implementation of IDs for theming with sprites;

There is a buggy way to get ID's in menu:
theme.inc
@1200

 foreach ($links as $key => $link) {
      $class = null;
      $meniitemid = $key;

further @1215

$output .= '<li'. drupal_attributes(array('id' => $meniitemid)) .' ';
      if($class) { //$class declared as null, so if nothing added no need to dispaly class attribute
      	$output .= drupal_attributes(array('class' => $class));
      }
      $output .= '>';

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.

alexanderpas’s picture

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