function IconMimeTypes::getIconClass

Same name and namespace in other branches
  1. 10 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.

1 call to IconMimeTypes::getIconClass()
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\file

Code

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.