This is a follow-up issue from the discussion at #489888: alt attribute set for node fields rendered as link produces not compliant HTML.
Node links currently always render a title attribute, but this is not a best practice when that title matches the actual link text. The title attribute is not required, and it is actually bad for accessibility and usability when it duplicates the link text.
Think about these situations:
1. A screen reader is speaking a page, and upon reaching one of these links, will read out both the link text, and the title attribute. So the visitor is now subjected to the same text twice for no apparent reason.
2. I'm just browsing the site and move my cursor over a link. A tooltip pops up showing me text, which I am conditioned to skim and expect to provide me additional information about the link. But instead, it's the same as the link text and ends up eating a second of my time as I have to process that basically useless info.
Links should only have a title when it contains additional, non-critical information about the destination.
So I recommend adding a simple comparison to not show the title in this situation. This quick fix means just changing line 519 of views_handler_field.inc from:
if ($alt) {
to
if ($alt && $alt != $text) {
If you think this is a good idea, could someone write a patch? ...I'm still learning how to do that part. Version 6.x-3.x-dev would also need this patch on line 599.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 507884-views-alt.patch | 1.5 KB | TheRec |
Comments
Comment #1
merlinofchaos commentedI would not be against such a patch.
Comment #2
TheRec commentedWell, here's a patch.
The feature seems limited to me anyways, we cannot set the "alt" title when using "Link this field to its node", we have to use "Output this field as a link" and fetch the path of the link from another field (for example "Node: Link") and use the token made available. So to give more power maybe the "Link this field to its node" should offer the same advanced settings than "Output this field as a link" ... but this should be asked in a feature request I guess.
I removed another line with this patch, when using "Link this field to its node" we do not need to set
$this->options['alter']['alt'] = check_plain($data);which will later set the "title" attribute of the link to the title of the node because it would anyways never verify this new condition :$alt != $textThe only case where those two would have been different using "Link this field to its node" would be if the title of the node would contain HTML code that would have been stripped with check_plain, and in this case I do not see the point in putting it as "title"... the raw content is the same so setting "title" does not make sense.
I tested when setting "Alternative text" (This should maybe get another name.. like "Link Title") with "Output this field as a link" and it works, it is displayed only if the text of the link is different of the "Alternative text" set (with or without using tokens), also tested "Link this field to its node" which does not output anymore title as expected.
Patch applies to Views HEAD (2.x-dev)... and also to 3.x-dev, without offset, but I only tested applying... not the functionality.
Comment #3
zroger commented+1.
I've found another similar issue with the title attribute, which stems from #377896: When ticked "link to node" show node title as a href title attribute. Since the title attribute is filled with the field value, if that value is not plain text, i.e. and img tag, you get the entire check_plain()'ed img tag in the title attribute. This is really unsightly in the tooltip.
Comment #4
Michael Zetterberg fd. Lopez commented+1
Since patch applied to HEAD 2.x-dev and 3.x-dev
Patch manually applied and worked as expected with Views 6.x-2.6 on my Drupal sites. So functionality wise it is ok in my opinion. I actually did the same edit myself before I found this patch.
I do agree with TheRec regarding the limited functionality and that the "fix" would be a feature request ultimately, but at least for now we get clean markup which makes more sense accessibility wise and validates too. Great work!
Comment #5
upupax commentedview 6.x-2.x-dev + patch = worked!
No more validation errors!
Thanks a lot!
Comment #6
TheRec commentedThird "ok" review should be enough to set it RTBC ;)
Comment #7
vitis commented507884-views-alt.patch worked for me! There is now no unwanted hover text for my images in Firefox. See below link for my specific problem.
Patch applied to Views 6.x-2.x-dev (2009-Jul-01).
FYI for others using this patch:
patch is for 2 different files
clear view's cache to see results
"Remove matching title attribute on node links" may also be related to Hover text problem in image . I posted a link to this node there.
Comment #8
ayalon commentedGreat patch! This one solved all my XHTML Validation issues. The wrong alt tag on node links is now gone! Please commit this to the next views release.
Comment #9
mattiasj commentedExcellent, please commit!
Comment #10
dwwNot only was the title attribute duplicate with the link text, it was getting escaped, even though it doesn't need to be, which leads to HTML entities in the pop-up text, etc. Reviewed, tested, and got Earl's blessings, so I committed to HEAD (6.x-2.x-dev) and DRUPAL-6--3. Thanks!