function IconMimeTypes::getIconClass
Same name in other branches
- 11.x core/modules/file/src/IconMimeTypes.php \Drupal\file\IconMimeTypes::getIconClass()
Gets a class for the icon for a MIME type.
Parameters
string $mimeType: A MIME type.
Return value
string A class associated with the file.
2 calls to IconMimeTypes::getIconClass()
- file_icon_class in core/
modules/ file/ file.module - Gets a class for the icon for a MIME type.
- template_preprocess_file_link in core/
modules/ file/ file.module - Prepares variables for file link templates.
File
-
core/
modules/ file/ src/ IconMimeTypes.php, line 21
Class
- IconMimeTypes
- A utility class for working with MIME types.
Namespace
Drupal\fileCode
public static function getIconClass(string $mimeType) : string {
// Search for a group with the files MIME type.
$genericMime = (string) self::getGenericMimeType($mimeType);
if (!empty($genericMime)) {
return $genericMime;
}
// Use generic icons for each category that provides such icons.
foreach ([
'audio',
'image',
'text',
'video',
] as $category) {
if (str_starts_with($mimeType, $category)) {
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.