function file_icon_class

Same name in other branches
  1. 8.9.x core/modules/file/file.module \file_icon_class()
  2. 10 core/modules/file/file.module \file_icon_class()

Gets a class for the icon for a MIME type.

Parameters

string $mime_type: A MIME type.

Return value

string A class associated with the file.

1 call to file_icon_class()
template_preprocess_file_link in core/modules/file/file.module
Prepares variables for file link templates.

File

core/modules/file/file.module, line 1544

Code

function file_icon_class($mime_type) {
    // Search for a group with the files MIME type.
    $generic_mime = (string) file_icon_map($mime_type);
    if (!empty($generic_mime)) {
        return $generic_mime;
    }
    // Use generic icons for each category that provides such icons.
    foreach ([
        'audio',
        'image',
        'text',
        'video',
    ] as $category) {
        if (strpos($mime_type, $category) === 0) {
            return $category;
        }
    }
    // If there's no generic icon for the type the general class.
    return 'general';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.