This was a request from one of the theme devs working on the Twig conversion. I'm moving it to a feature request here so I can take the TODO out of our template file.

I believe active links already get a special class, so we may end up using the active class that's there already for this purpose (so marking the issue as minor)

Comments

c4rl’s picture

Title: Create an 'active' flag in theme_link so that classes can be easily added if the link is active » Create an .active class callback for attributes on links
Issue tags: +theme system cleanup

Altering title slightly

c4rl’s picture

I have a daring proposal:

What if this were part of ArrayAccess::offsetSet? Meaning, when href was set, it would run the .active class check and if it were the case, call $this->offsetSet('class', 'active');

c4rl’s picture

:) Potential issue with daring proposal in #2

Looking at l(), since the .active class is checked against $path and href is set to url($path, $options), there would need to be a way to clarify this. Checking against a static set in url() is a potential solution.

sun’s picture

I have troubles to understand this issue, as I don't see a concrete feature request for what is actually wanted anywhere.

"Create an .active CSS class on a link (A) element based on its attributes" is all what I got so far, but that makes 0% sense.

A link gets .active if its href matches the currently requested page. If it doesn't have an href, it cannot get active.

The .active class is specific to the current page and not to be mistaken with the .active-trail class, which is special to links appearing in menu link trees.

c4rl’s picture

Title: Create an .active class callback for attributes on links » Add an .active class for links that have an href to the URL being viewed
Status: Active » Postponed

I can see what happens when I am up too late in the issue queue. :) Wild ideas.

I thought about this some more and discussed with jenlampton, and it seems for the majority of use cases, having a .active class on a link only seems pertinent to navigational items, where the given link in the should change in appearance. Indeed, this is something we've had in Drupal a long time, but it's traditionally been part of the l() function, not part of menu theming. Given all the related discussion about l() and theme links, I'm going to mark this as postponed as we may discover that refactoring menu theming to add the .active class instead of l() is a way forward.

thedavidmeister’s picture

Title: Add an .active class for links that have an href to the URL being viewed » Add an .active class for links rendered by theme('link') that have an href to the URL being viewed and sanitize output of url()
Priority: Minor » Normal
Status: Postponed » Active

Making the title reflect more accurately what (I think) is being asked. l() already handles the .active class. Correct me if I'm wrong but I think the intention here is really to make sure that theme_link() (if not overridden by the theme system) produces the same output for l() consistently if it receives the same input.

That way the changes proposed in #1778610: Remove the check for a link template from l(), have l() always output just a string. become much more palatable.

thedavidmeister’s picture

Status: Active » Closed (duplicate)

This is now a duplicate with #1778616: Add an .active class for links rendered by theme('link') that have an href to the URL being viewed and sanitize output of url(). Even though this issue is older, that one has a patch that's looking close to RTBC.