diff options
author | David Rothstein <drothstein@gmail.com> | 2015-10-12 19:46:01 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2015-10-12 19:46:01 -0400 |
commit | 830fdeac5a7e176a66443e4975bf9ca58d1a18ab (patch) | |
tree | c73610931d145a4dbf04448c9ef7f0a5849ad11a /modules | |
parent | 566312388ac7fdfd24bfa3c98e85d5c26eb4776c (diff) | |
download | brdo-830fdeac5a7e176a66443e4975bf9ca58d1a18ab.tar.gz brdo-830fdeac5a7e176a66443e4975bf9ca58d1a18ab.tar.bz2 |
Issue #2163209 by mgifford, David_Rothstein, andrewmacpherson, talhaparacha, dcam, Charles Belov, davidhernandez, jwhitsit: Add alternate text to file icon
Diffstat (limited to 'modules')
-rw-r--r-- | modules/file/file.module | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/modules/file/file.module b/modules/file/file.module index ae452a683..fbf8b81ec 100644 --- a/modules/file/file.module +++ b/modules/file/file.module @@ -92,7 +92,7 @@ function file_theme() { 'variables' => array('file' => NULL, 'icon_directory' => NULL), ), 'file_icon' => array( - 'variables' => array('file' => NULL, 'icon_directory' => NULL), + 'variables' => array('file' => NULL, 'icon_directory' => NULL, 'alt' => ''), ), 'file_managed_file' => array( 'render element' => 'element', @@ -749,7 +749,32 @@ function theme_file_link($variables) { $icon_directory = $variables['icon_directory']; $url = file_create_url($file->uri); - $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory)); + + // Human-readable names, for use as text-alternatives to icons. + $mime_name = array( + 'application/msword' => t('Microsoft Office document icon'), + 'application/vnd.ms-excel' => t('Office spreadsheet icon'), + 'application/vnd.ms-powerpoint' => t('Office presentation icon'), + 'application/pdf' => t('PDF icon'), + 'video/quicktime' => t('Movie icon'), + 'audio/mpeg' => t('Audio icon'), + 'audio/wav' => t('Audio icon'), + 'image/jpeg' => t('Image icon'), + 'image/png' => t('Image icon'), + 'image/gif' => t('Image icon'), + 'application/zip' => t('Package icon'), + 'text/html' => t('HTML icon'), + 'text/plain' => t('Plain text icon'), + 'application/octet-stream' => t('Binary Data'), + ); + + $mimetype = file_get_mimetype($file->uri); + + $icon = theme('file_icon', array( + 'file' => $file, + 'icon_directory' => $icon_directory, + 'alt' => !empty($mime_name[$mimetype]) ? $mime_name[$mimetype] : t('File'), + )); // Set options as per anchor format described at // http://microformats.org/wiki/file-format-examples @@ -779,16 +804,19 @@ function theme_file_link($variables) { * - file: A file object for which to make an icon. * - icon_directory: (optional) A path to a directory of icons to be used for * files. Defaults to the value of the "file_icon_directory" variable. + * - alt: (optional) The alternative text to represent the icon in text-based + * browsers. Defaults to an empty string. * * @ingroup themeable */ function theme_file_icon($variables) { $file = $variables['file']; + $alt = $variables['alt']; $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 . '" />'; + return '<img class="file-icon" alt="' . check_plain($alt) . '" title="' . $mime . '" src="' . $icon_url . '" />'; } /** |