Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you're like me and you needed the 'active' class on the active LI element and not just the A, then put this code
if (isset($menu_item['link']['href']) && ($menu_item['link']['href'] == $_GET['q'] || ($menu_item['link']['href'] == '<front>' && drupal_is_front_page()))
&& (empty($menu_item['link']['language']) || $menu_item['link']['language']->language == $language_url->language)) {
$item_class[] = 'active';
}
just underneath this line
$mlid = $menu_item['link']['mlid'];
in your superfish.module file, which for me was on line 944. Currently, the Superfish module doesn't seem to support language neutral links, because there is no $menu_item['link']['language'] in the $menu_item array it builds. I left it in however in case support comes out in the future.
This is a feature request.. It'd be great to be able to apply markup to active elements in the menu config, much as you can wrap html / css around elements now.
Comments
Comment #1
mehrpadin CreditAttribution: mehrpadin commentedHey Shawn,
Is there anything wrong with the
active-trail
class? :)Comment #2
mehrpadin CreditAttribution: mehrpadin commentedComment #3
danielgeez CreditAttribution: danielgeez commentedThere's nothing wrong with the active-trail class. We just want to be able to apply it to the LI item as well as the A. I'm using the latest version and this module still doesn't seem to allow this.
Comment #4
danielgeez CreditAttribution: danielgeez commentedComment #5
mehrpadin CreditAttribution: mehrpadin commentedHey there,
Can you tell me why exactly would you need that? I mean, you can easily select active
<li>
elements already:Or if it's the link inside it:
?
Comment #6
dwwThe reason you want the "active" class on the
<li>
itself, not just relying on active-trail and having "active" on the<a>
, is for the superfish.js feature "sf-smallscreen-select". See libraries/superfish/sfsmallscreen.js and search for "addSelected" to see what I'm talking about. That feature doesn't work at all unless you overridetheme_superfish_menu_item()
to set the 'active' class manually (like core itself does).Since the lack of this class is breaking a feature provided by this module, calling this a bug.
Comment #7
mehrpadin CreditAttribution: mehrpadin commentedHey there,
Allow me to disagree :)
A) Core does not do that, it however does give
<a>
elements anactive-trail
class in addition to their parent<li>
lately - for whatever reason that is unknown to me and actually hardly makes any sense either etc etc.B) If you're referring to the line #88 (master branch) of the sfsmallscreen.js, I'm afraid it's looking for the class not on
<li>
elements but on<a>
& possible<span>
elements, look at the line #78 whereparent
is defined.Thanks for your comment anyway, and please revert to feature request, thank you.
Comment #8
dwwRe: A) I dunno. ;)
Re: B) I figured it out a while ago, and forgot to post back here. You also need to enable the "Copy the hyperlink classes to the
<option>
elements of the<select>
" checkbox for the "sf-smallscreen-select" feature to work. It'd be nice if that was documented or even toggled via #states or something so that if you turn on sf-smallscreen-select it automatically checks this other setting for you. Perhaps that should be moved into a separate feature request.Cheers,
-Derek
Comment #9
LOBsTerr CreditAttribution: LOBsTerr at European Commission and European Union Institutions, Agencies and Bodies commented