Hi,

currently single menu items are cosidered as last items in the list.
Would it be possible to consider them also as first items?

I don't know if the attached patch can break some themes, alternatively marking single menu items as single-menu-item could work as well, as suggested in [#138656].

Regards,
Antonio

Comments

mr.baileys’s picture

Title: Use both first and last class for single menu items. » Use both first and last class for single-item menu item.
Version: 6.10 » 7.x-dev
Category: feature » bug
Status: Needs review » Needs work
Issue tags: +Quick fix

Ran into the same issue today. I'd classify this as a bug. If a menu item is the first, it should have the class "first", if it's the last item it should have a class "last", and if it's the only item, it should have both classes.

Current practice is to fix this in 7.x-dev first though, and then backport it to D6.

Not sure about:

$extra_class .= ' last';

Feels a bit messy since $extra_class might be NULL and the space is only required in very specific circumstances (single-item menu) anyway. What about treating $extra_class as an array:

    $extra_class = array();		
    if ($i == 0) {
      $extra_class[] = 'first';
    }
    if ($i == $num_items - 1) {
      $extra_class[] = 'last';
    }
    $link = theme('menu_item_link', $data['link']);
    if ($data['below']) {
      $output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], implode(' ', $extra_class));
    }
    else {
      $output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], implode(' ', $extra_class));
    }
ao2’s picture

Yes that will work as well, or if we want to use the same style used in theme_item_list, we could do:

Index: drupal/includes/menu.inc
===================================================================
--- drupal.orig/includes/menu.inc
+++ drupal/includes/menu.inc
@@ -753,7 +753,7 @@
       $extra_class = 'first';
     }
     if ($i == $num_items - 1) {
-      $extra_class = 'last';
+      $extra_class = empty($extra_class) ? 'last' : $extra_class . ' last';
     }
     $link = theme('menu_item_link', $data['link']);
     if ($data['below']) {

Regards,
Antonio

mr.baileys’s picture

That looks cleaner than my solution. Would you mind rolling a new patch?

ao2’s picture

Status: Needs work » Needs review
StatusFileSize
new634 bytes

Ok,

I rebased the code above to apply cleanly on drupal7, the patch still applies to drupal6 tho.

Regards,
Antonio

Status: Needs review » Needs work

The last submitted patch failed testing.

ao2’s picture

Status: Needs work » Needs review
StatusFileSize
new782 bytes

Mmh, the System Message says Failed: Failed to apply patch....

I guess it's because the patch I sent was made with quilt which put also the parent directories in paths (which, in general, is good IMHO), let's try with a 'p0' patch as it expects.

Regards,
Antonio

andypost’s picture

Status: Needs review » Reviewed & tested by the community

another great patch, tested and this works as expected ... now theme can check for this case.
RTBC

dries’s picture

Status: Reviewed & tested by the community » Fixed

We usually add the classes to an array, and than we simply explode them. Sounds like it would be more elegant. One more re-roll?

Do we have tests for this, or do we feel that is unnecessary?

andypost’s picture

Status: Fixed » Needs review
StatusFileSize
new986 bytes

Suppose better reroll to unify :)
I see nothing to test...

dries’s picture

Version: 7.x-dev » 6.x-dev

Committed to CVS HEAD! Moving version number. Thanks Andy.

andypost’s picture

So here reroll for d6

ao2’s picture

Hi, will this be added to D6 as well?

Thanks,
Antonio

andypost’s picture

Issue tags: +Needs backport to D6

If anyone review this - patch still applies cleanly
So add a tag

hefox’s picture

Patch works for me. :)

pvasili’s picture

#11 - good patch
Please use it for 6 versions!

ao2’s picture

Ping.

Can we have this in next Drupal6 release?

Thanks,
Antonio

andypost’s picture

Status: Needs review » Reviewed & tested by the community

There are more then 2 people test this so suppose RTBC

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Great, committed to Drupal 6 too, thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Needs backport to D6, -Quick fix

Automatically closed -- issue fixed for 2 weeks with no activity.