function 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.
1 call to IconMimeTypes::getIconClass()
- FileThemeHooks::preprocessFileLink in core/
modules/ file/ src/ Hook/ FileThemeHooks.php - 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.