I'd love be able to alter the links views creates in fields a bit more than is currently possible. render_as_link() allows a bit of customization, but there is no way to alter the link array that gets sent to l(). AFAICT, the only element we don't have access to is 'attributes', which gets auto-created and has a few keys added by this function (class, title, target).

I'd love the ability to add in arbitrary attributes. I can see this especially helpful with html5 data attributes, but it would also enable fixing #363702: rel="nofollow" for a views links manually. I can't really think of a good way to present this to the user, but it could just be an advanced developer feature that isn't exposed via the UI.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joshuajabbour’s picture

Status: Active » Needs review
FileSize
1.11 KB

The attached patch adds a $alter['link_attributes'] element, which should be an array of attributes passed to drupal_attributes(). It won't overwrite an attributes already set (like class, title, etc).

joshuajabbour’s picture

FileSize
1.11 KB

Different way of merging the attributes arrays...

merlinofchaos’s picture

Status: Needs review » Postponed (maintainer needs more info)

Well, we've recently added support for 'rel'. I think we actually now support, in the UI, almost all attributes, so I'm not sure there's any value to this any more.

Marking this NMI; if you have a good justification for why I'm incorrect, I'll listen -- just return to needs review. Otherwise the bug squad will close this won't fix in 30 days. =)

joshuajabbour’s picture

Status: Postponed (maintainer needs more info) » Needs review

The use case I have is to add html5-like "data-" attributes from inside a preprocessor. jQuery then automatically attaches these via the element's .data() method.

Without access at the level of this patch, the only way to do it is to either str_replace the output, or custom re-render the field content (but then you can't use render_as_link, which causes you to lose any settings that have been set for this link (like rel, etc) or any of the other things that happen in this method).

Basically, we need a pass-through to alter the whole attributes array l() gets passed, as opposed to just a few of the attributes keys.

merlinofchaos’s picture

Status: Needs review » Fixed

Ok, committed to all branches.

Status: Fixed » Closed (fixed)

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