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.
Comment | File | Size | Author |
---|---|---|---|
#2 | views-962564.patch | 1.11 KB | joshuajabbour |
#1 | views-962564.patch | 1.11 KB | joshuajabbour |
Comments
Comment #1
joshuajabbour CreditAttribution: joshuajabbour commentedThe 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).
Comment #2
joshuajabbour CreditAttribution: joshuajabbour commentedDifferent way of merging the attributes arrays...
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedWell, 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. =)
Comment #4
joshuajabbour CreditAttribution: joshuajabbour commentedThe 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.
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedOk, committed to all branches.