For accessibility reasons, meaningful images should have alt text.

theme_file_icon() adds empty alt text.

While the image is meaningful in that it conveys a file type, it could also be argued that because the screen reader can read the file name the user could determine the file type anyway.

So, should we have alt text or not?

Personally I don't see the harm in having alt text for these images, however I'm not someone who ouses screen readers so for all I know it might be annoying to have potentially redundant information.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rooby’s picture

I'm actually leaning towards it being redundant and therefore unwanted. But agreeance from someone else would be good too.

rooby’s picture

However in that case the image should also have empty or no title attribute.

Everett Zufelt’s picture

How does Drupal decide which icon to display, is it based on file extension? If so, I would argue that the alt text on the image is redundant (provided that the file name is always available in the link text, and that the alt text on the image should be null, e.g. "".

Otherwise, if the image and the file extension available to the user are not always the exact same thing, then the alt text on the image should be provided. At which time I'd love a list of images and a brief description of each so that we can determine the best alt text.

rooby’s picture

The icon is determined by the file mime type.

However now that you mention it, the theme function can be used anywhere, so there is no guarantee it will be displayed with the file name, or anything else that might describe the file type or make the image description redundant.
So it seems like alt text would be the way to go.

Ideally it would be something generated automatically from the mime type.
Maybe something along the lines of?:

<?php
$mime_parts = explode($mimetype);
$alt = t('A @subtype @type file icon', array('@subtype' => $mime_parts[1], '@type' => $mime_parts[0]));
?>
Everett Zufelt’s picture

Can you please provide a few example mimetype strings?

rooby’s picture

audio/mp4
audio/mpeg
image/jpeg
image/png
application/pdf
text/plain
text/csv

For more see http://en.wikipedia.org/wiki/MIME_type#List_of_common_media_types

Actually on second check (forgive my mistake, it's late), it isn't directly using mime type. It uses it in a round about way.
Some icon file names directly relate to the mime type (like pdf, plain text, html text), some use generic icons (all audio types are the same, video are the same etc), some are manually mapped via file_icon_map() (like ms office docs etc.) and application-octet-stream.png is a fallback icon.

So either we have an equally elaborate method of working out the alt text or it could potentially be based on the file name of the icon minus the extension or else based on the unaltered mime type like the title text is currently (it is just the mime type by itself).

Curse these tiny accessibility issues.

johnv’s picture

Status: Active » Needs review

coming from #1369616: file field formatters: also for images + new formatter 'mime-icon only', which asks for an mime-icon-only formatter, with filename in the alt-text.
The following shows the complete filename as alt-text.

function theme_file_icon($variables) {
  $file = $variables['file'];
  $icon_directory = $variables['icon_directory'];

-  $mime = check_plain($file->filemime);
-  $icon_url = file_icon_url($file, $icon_directory);
-  return '<img class="file-icon" alt="" title="' . $mime . '" src="' . $icon_url . '" />';

+  $title = isset($file->origname) ? check_plain($file->origname) : check_plain($file->filemime);
+  $icon_url = file_icon_url($file, $icon_directory);
+  return '<img class="file-icon" alt="" title="' . $title . '" src="' . $icon_url . '" />';
}
h3rj4n’s picture

I created a patch as suggested in comment #7. While I was creating the patch I figured that the origname doesn't exists? It isn't in the documentation on this page. Changed it to the filename. I'm not sure if that's the best way.

Any other solutions I can think of need extra variables to be passed on to the them function. That's also the case in patch #1369616: file field formatters: also for images + new formatter 'mime-icon only' comment 6.

andymartha’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
83.06 KB
69.16 KB

I can confirm that the patch in #8 changes the file icon image title in uploaded files from "image/jpeg" to "filename.jpg" without breaking anything in Drupal 8.x-dev. See attached images of before and after the patch.
Good job, but not sure if it closes the issue.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This should have automated tests.

plopesc’s picture

Hello

I'm working on this issue as part of core mentoring hours (http://core.drupalofficehours.org/task/1897).

I don't know if tests for this issue should test the file name in theme_file_icon() or test the whole theme_file_link() process, including the icon name generation, the link itself, etc.

I'm proposing a first approach.

Please give me feedback.

Regards

h3rj4n’s picture

Status: Needs work » Needs review

I think you have to set the status of this issue to needs review before it will be tested.

rooby’s picture

+++ b/core/modules/file/file.module
@@ -1286,9 +1286,9 @@ function theme_file_icon($variables) {
+  $title = !empty($file->filename) ? check_plain($file->filename) : check_plain($file->filemime);

I think I prefer the approach in #1369616-6: file field formatters: also for images + new formatter 'mime-icon only', where you can pass in the title if you would like to. However, I also think that if no title is passed in that the title should be an empty string.
Like so:

<?php
  $title = isset($variables['title']) ? $variables['title'] : '';
?>

I really can't see people wanting to see the mime type of a document, it's gibberish to most people.
Also, it really doesn't add any value. The icon is almost always positioned next to text containing the file name, and if not people can pass their own title value in.

Another thing to be careful of is having an image with meaning, with no alt text, but with meaningful title text. This is generally an accessibility no-no.
Meaningful images should have meaningful alt text, but don't really need meaningful title text.

Title text is not necessarily read by screen readers and is not a replacement for alt text.

If the title text is not really that valuable and it wouldn't matter to a screen reader user if they didn't read the title text, then it is more of a grey area, in which case do we really need title text at all?
Isn't no title text better than gibberish title text?

loopy1492’s picture

Subscribing.

Is there a way to tell if this bug is being worked on for 7.x as well?

rooby’s picture

@loopy1492:

The bug will be fixed in drupal 8 first, then backported to drupal 7 in this same issue.

At any stage, if someone wants to they can create a drupal 7 version of the patch and post it here for people to use on drupal 7 in the meantime.

In that case the patch file should be named so that the test bot skips it. Otherwise it will try to patch drupal 8 with a drupal 7 patch and fail. See https://drupal.org/node/332678#skipping for more information.

pandaPowder’s picture

It sounds like you already have a direction chosen based on the patches submitted, but my opinion is that any image that conveys information should have that same information conveyed in the alt text. Decorative only images should have alt=""
File type icons certainly convey information beyond what might be displayed in the text of the link. The text of the link might be a descriptor for the file, or it might be the filename. I think most clients/slighted users would prefer a descriptor. Therefore, the icon itself is mainly responsible for conveying the file type. Therefore, we should set the alt text based on the mime type.

In the case of direct mappings, this would be great to let screen reader users know what they're clicking on. In the case of fallbacks and generic audio files, the alt text should be as generic as the file type icon. A generic file type icon conveys a certain amount of information to the sighted user (such as audio or video to use your example) which is the same information that should be conveyed in the alt text.

for reference:
http://webaim.org/techniques/alttext/

mgifford’s picture

Issue tags: +Accessibility

Tagging.

Also, for reference https://drupal.org/node/465106#alt-text

mgifford’s picture

Issue tags: -Needs tests, -Accessibility

Status: Needs review » Needs work
Issue tags: +Needs tests, +Accessibility

The last submitted patch, title_to_img-1507754-combined.patch, failed testing.

h3rj4n’s picture

Status: Needs work » Needs review
FileSize
2.95 KB

I rerolled the patch. Also set the alt text to the mime type because of comment #16.

I wasn't able to create a interdiff.

h3rj4n’s picture

Previous one was a merge commit / diff. I'm not sure if the test bot is able to apply that one. This one should be the good one.

The last submitted patch, drupal-icon_alt-1507754-21.patch, failed testing.

mgifford’s picture

Status: Needs work » Needs review
mgifford’s picture

Status: Needs review » Needs work

The last submitted patch, 21: drupal-icon_alt-1507754-21.patch, failed testing.

johnv’s picture

OK, let's use the new tools to link issues.

Charles Belov’s picture

I'm sorry I missed this issue when I created #2163209: Add alternate text to file icon. It appears I've created a duplicate.

As to the comment whether this icon is purely decorative, that question seems to revolve on the fact that in a list of files, the file extension is seen. However:

1) If the file is inserted into Body text, the file name may be replaced with text describing the content. Therefore, an extension might not be shown and the icon would definitely not be docorative.

2) Operating systems often hide the extension by default, not on the web page but on the computer; therefore website visitors may not be sensitized to the existence of file extensions and the presence of extensions on a website might even be mysterious to them. (It would, however, be a separate issue as to whether to hide the file extension in a file list and just rely on the file type icon.)

As I stated in #2163209, I agree that MIME types are gibberish to most website visitors and do not belong in either the alt text or the title text.

mgifford’s picture

Status: Needs work » Closed (duplicate)

Marking this one as a duplicate. Mostly because the mime type isn't a good alt text and the other issue is addressing that.