diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 47b72ef..c3014a5 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -1633,106 +1633,51 @@ function theme_file_link($variables) {
$options['attributes']['title'] = check_plain($file->getFilename());
}
- $file_icon = array(
- '#theme' => 'file_icon',
- '#file' => $file,
- '#icon_directory' => $variables['icon_directory'],
- );
-
- return '' . drupal_render($file_icon) . ' ' . l($link_text, file_create_url($file->getFileUri()), $options) . '';
-}
-
-/**
- * Returns HTML for an image with an appropriate icon for the given file.
- *
- * @param $variables
- * An associative array containing:
- * - file: A file entity 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 "icon.directory"
- * variable.
- *
- * @ingroup themeable
- */
-function theme_file_icon($variables) {
- $file = $variables['file'];
- $icon_directory = $variables['icon_directory'];
-
- $mime = check_plain($file->getMimeType());
- $icon_url = file_icon_url($file, $icon_directory);
- return '
';
-}
-
-/**
- * Creates a URL to the icon for a file entity.
- *
- * @param \Drupal\file\File $file
- * A file entity.
- * @param $icon_directory
- * (optional) A path to a directory of icons to be used for files. Defaults to
- * the value of the "icon.directory" variable.
- *
- * @return
- * A URL string to the icon, or FALSE if an appropriate icon cannot be found.
- */
-function file_icon_url(File $file, $icon_directory = NULL) {
- if ($icon_path = file_icon_path($file, $icon_directory)) {
- return base_path() . $icon_path;
+ // Set file classes to the options array.
+ if (isset($options['attributes']['class']) && is_array($options['attributes']['class'])) {
+ $options['attributes']['class'] = array_merge($options['attributes']['class'], file_icon_classes($file));
}
- return FALSE;
+ else {
+ $options['attributes']['class'] = file_icon_classes($file);
+ }
+
+ return l($link_text, file_create_url($file->getFileUri()), $options);
}
/**
- * Creates a path to the icon for a file entity.
+ * Creates a list of classes to the icon for a file entity.
*
* @param \Drupal\file\File $file
* A file entity.
- * @param $icon_directory
- * (optional) A path to a directory of icons to be used for files. Defaults to
- * the value of the "icon.directory" variable.
*
* @return
- * A string to the icon as a local path, or FALSE if an appropriate icon could
- * not be found.
+ * A array of the classes associated to the file.
*/
-function file_icon_path(File $file, $icon_directory = NULL) {
- // Use the default set of icons if none specified.
- if (!isset($icon_directory)) {
- $icon_directory = \Drupal::config('file.settings')->get('icon.directory');
- }
+function file_icon_classes(File $file) {
+ $classes = array();
- // If there's an icon matching the exact mimetype, go for it.
- $dashed_mime = strtr($file->getMimeType(), array('/' => '-'));
- $icon_path = $icon_directory . '/' . $dashed_mime . '.png';
- if (file_exists($icon_path)) {
- return $icon_path;
- }
-
- // For a few mimetypes, we can "manually" map to a generic icon.
+ // Search for a group with the files MIME type.
$generic_mime = (string) file_icon_map($file);
- $icon_path = $icon_directory . '/' . $generic_mime . '.png';
- if ($generic_mime && file_exists($icon_path)) {
- return $icon_path;
+ if (!empty($generic_mime)) {
+ $classes[] = $generic_mime;
}
// Use generic icons for each category that provides such icons.
foreach (array('audio', 'image', 'text', 'video') as $category) {
- if (strpos($file->getMimeType(), $category . '/') === 0) {
- $icon_path = $icon_directory . '/' . $category . '-x-generic.png';
- if (file_exists($icon_path)) {
- return $icon_path;
- }
+ if (strpos($file->getMimeType(), $category) === 0) {
+ $classes[] = $category;
}
}
- // Try application-octet-stream as last fallback.
- $icon_path = $icon_directory . '/application-octet-stream.png';
- if (file_exists($icon_path)) {
- return $icon_path;
+ // If there's no generic icon for the type use a specific one.
+ if (empty($classes)) {
+ $dashed_mime = strtr($file->getMimeType(), array('/' => '-'));
+ $classes[] = $dashed_mime;
+ $classes[] = 'file-general';
}
+ $classes[] = 'file';
- // No icon can be found.
- return FALSE;
+ return $classes;
}
/**
@@ -1763,7 +1708,8 @@ function file_icon_map(File $file) {
case 'application/x-applix-word':
case 'application/x-kword':
case 'application/x-kword-crypt':
- return 'x-office-document';
+ case 'application/rtf':
+ return 'office-document';
// Spreadsheet document types.
case 'application/vnd.ms-excel':
@@ -1779,7 +1725,7 @@ function file_icon_map(File $file) {
case 'application/x-gnumeric':
case 'application/x-kspread':
case 'application/x-kspread-crypt':
- return 'x-office-spreadsheet';
+ return 'office-spreadsheet';
// Presentation document types.
case 'application/vnd.ms-powerpoint':
@@ -1791,7 +1737,7 @@ function file_icon_map(File $file) {
case 'application/vnd.sun.xml.impress':
case 'application/vnd.sun.xml.impress.template':
case 'application/x-kpresenter':
- return 'x-office-presentation';
+ return 'office-presentation';
// Compressed archive types.
case 'application/zip':