There is always an "alt" attribute for all the links generated by "Views" and this is not compliant with the W3C recommendations, the "a" tag does not have an "alt" attribute. The "title" attribute, that is set at the same time, is the right way to provide a more complete and more accessible description of the link... so I guess we should remove this "alt", but since I am not experienced with Views and all its functionality I think it is better just to report this and let a qualified "Views" developer handle this ;)

I located two place where Views could be modified to remove "alt", but I don't want to create the patch for this, because I am pretty sure that this code has a reason to exist (for images maybe ?), so maybe this helps to nail down the problem.
Near line 517, modules/views/handlers/views_handler_field.inc :

    $alt = $this->options['alter']['alt'];
    $alt = strtr($alt, $tokens);

Near line 517, modules/views/modules/node/views_handler_field_node.inc :
$this->options['alter']['alt'] = check_plain($data);
Hopefully this will help... oh and this might very well have been introduced with the patch committed in #399534: Add fragment and query to render_as_link, because before Views wasn't adding this "alt" attribute.

CommentFileSizeAuthor
#27 views-489888-1.patch540 bytesgargoyle
#2 views-489888.patch612 bytesTheRec
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TheRec’s picture

Hmm my bad... that other issue has surely not introduced this bug, it seems that this code was there already before that patch.
But this one did I think : #377896: When ticked "link to node" show node title as a href title attribute

TheRec’s picture

Status: Active » Needs review
FileSize
612 bytes

Well, I'll give it a try... after few tests and since this function is called "render_as_link" (so it shouldn't render anything else), I think it is safe to just remove the "alt" attribute of links.

TheRec’s picture

Version: 6.x-2.6 » 6.x-2.x-dev
Assigned: Unassigned » TheRec
Dret’s picture

Category: bug » feature

Hi to all and Thanks for the patch!

A request more... if possible:

For Web Accessibility standard all link must have the "title" attributes (and all the images the "alt" one).

It's possible in the next releases to work for this target?

The last patch correct the problem above but actualy not all link field have the "title" avaiable.

Thanks!
Bye!

TheRec’s picture

Sure this should be worked, at least the possibility set the "title" attribute of anchors, if wanted/needed (it should not be an obligation) and "alt" attribute should be mandatory for images (even if it is empty..). Anyways you should create an issue for this in my opinion, that patch (for a bug!) still needs to be reviewed before maybe being committed. Making this issue a feature request won't help to correct that bug.

TheRec’s picture

Category: feature » bug
balabushka’s picture

Subscribing... also suffering from that bug :-)

antiorario’s picture

Subscribing.

B00N’s picture

Subscribing.

merlinofchaos’s picture

If you subscribed and did not test and report on the patch, SHAME ON YOU.

gbrussel’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed. Applied the patch, links no longer spits out the alt="" attribute anymore. If you could do the same for removing image title="" in this patch (unless that would kill kittens), it'd be nice.

TheRec’s picture

I would really like to find where the "title" might be set for img, but I cannot find any place in Views where it renders images with such attribute (in fact I couldn't find a place where image are rendered with views handler or other parts of the module :) ... it is not my module, but I searched the code with 'img', 'image' 'title', and 'alt' and nothing relevant showed up)... wouldn't it rather be an issue in CCK or ImageField or Image ? If so, then you should create an issue in their queue.

fenstrat’s picture

Confirmed, works as stated - the invalid alt attributes on <a> elements are gone.

The title tag should not be removed as it is valid html.

TheRec’s picture

Thanks for the feedback.
Sure it won't (at least in my opinion)... but it should be optional for anchors (<a>), because it is optional in some cases (for example when the anchor text is describing the content of the link with enough details). So maybe, if anyone needs it, he/she could make a feature request to make this "title" attribut optional ;)

shelleyp’s picture

Just wanted to confirm that the patch worked on my seven Drupal sites. Thanks!

VM’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev

This would need to be added to 3.x-dev as well, patch does indeed apply to 3.x and does indeed remove the alt tag from <a>

andyceo’s picture

Sorry, may be this is offtopic, but something like that problem we discover here: A wrong "alt" and "title" attributes in "a" tag for imagecache images.

auberdjinn’s picture

Thanks, this patch worked for me.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 2.x and 3.x branches.

DamienMcKenna’s picture

As someone who just ran into this little bug, thanks to all who contributed to getting it resolved!

GuillaumeDuveau’s picture

Same as Damien, thanks everybody !

noahterp’s picture

I wanted to point out that the title attribute is not required on links. It is actually bad for accessibility and usability if the title is simply duplicating the actual 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.

"Web accessibility" standards only say to use the title when it has additional, non-critical information about the link. So I recommend adding a quick comparison and not showing the title attribute if it's identical to the link text.

That quick fix should just mean changing line 519 of views_handler_field.inc from:
if ($alt) {
to
if ($alt && $alt != $text) {

GuillaumeDuveau’s picture

Good point, but could you post this as a new issue please ?

TheRec’s picture

Thanks for the precision noahterp, that was exactly my point in #14 ;)

noahterp’s picture

Sorry, I thought I would continue this discussion (since the title attribute was mentioned a few times) instead of making a new issue. It's now listed at #507884: Remove matching title attribute on node links.

Status: Fixed » Closed (fixed)

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

gargoyle’s picture

Status: Closed (fixed) » Needs work
FileSize
540 bytes

Sorry for re-opening this, but I was following through this thread after discovering the same issue with one of my sites. However, I patched .../views/modules/node/views_handler_field_node.inc which includes a very similar line to the one from the previous patch...

Line 48 should be removed I think.

I have attached a patch, but it is my first one - ever. So someone else should check I have done everything correctly...

TheRec’s picture

Status: Needs work » Closed (fixed)

This is not related to the original issue. And what you are doing in your patch is already waiting to be reviewed here (for a moment) : #507884: Remove matching title attribute on node links

Mac Clemmens’s picture

Tested and works great!

ridolfidesigns’s picture

I am running ver 2.6 for Drupal 6 and I am still receiving this problem.

TheRec’s picture

Most likely because the version you run was out on "2009-Jun-10" and this issue started on "June 12, 2009" and the fix got commited on "June 26, 2009 - 00:04". In short words, you'll see this in the next stable, right now it is only in the -dev snapshot and on CVS.

ridolfidesigns’s picture

Ah yes, thank you for that little detail. I will run the patch.

lennartalserda’s picture

Thanks for this patch.

I seems t work fine :)

mgifford’s picture

Yup. We ran into this issue too. alt tags should never be used with an anchor. Please bring views-489888-1.patch into core!

gmh04’s picture

This patch works for me

Narno’s picture

views-489888-1.patch works for me too! thx

Summit’s picture

Hi, Is this patch also in latest 2.8 views?
Greetings, Martijn

archimedes’s picture

This patch was committed and put into the Views 6.x-2.7 (http://drupal.org/node/621428) release. It should thus carry over to 6.x-2.8.

nocean’s picture

I'm using Views 6.x-2.11 and am seeing "Alt text:" in the "Output this field as a link" section, with no ability to add a "title" attribute. Did this fall off somewhere between 2.7 and 2.11?