hook_file_mimetype_mapping_alter

hook_file_mimetype_mapping_alter(&$mapping)

Alter MIME type mappings used to determine MIME type from a file extension.

Invoked by \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess(). It is used to allow modules to add to or modify the default mapping from \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::$defaultMapping.

Parameters

$mapping: An array of mimetypes correlated to the extensions that relate to them. The array has 'mimetypes' and 'extensions' elements, each of which is an array.

See also

\Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess()

\Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::$defaultMapping

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/lib/Drupal/Core/File/file.api.php, line 117
Hooks related to the File management system.

Code

function hook_file_mimetype_mapping_alter(&$mapping) {
  // Add new MIME type 'drupal/info'.
  $mapping['mimetypes']['example_info'] = 'drupal/info';
  // Add new extension '.info.yml' and map it to the 'drupal/info' MIME type.
  $mapping['extensions']['info'] = 'example_info';
  // Override existing extension mapping for '.ogg' files.
  $mapping['extensions']['ogg'] = 189;
}
doc_Drupal
2016-10-29 09:18:13
Comments
Leave a Comment

Please login to continue.