function hook_file_mimetype_mapping_alter
Same name in other branches
- 7.x modules/system/system.api.php \hook_file_mimetype_mapping_alter()
- 9 core/lib/Drupal/Core/File/file.api.php \hook_file_mimetype_mapping_alter()
- 8.9.x core/lib/Drupal/Core/File/file.api.php \hook_file_mimetype_mapping_alter()
- 11.x core/lib/Drupal/Core/File/file.api.php \hook_file_mimetype_mapping_alter()
Alter MIME type mappings used to determine MIME type from a file extension.
Invoked by \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guessMimeType(). 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::guessMimeType()
\Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::$defaultMapping
Related topics
1 function implements hook_file_mimetype_mapping_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- file_test_file_mimetype_mapping_alter in core/
modules/ file/ tests/ file_test/ file_test.module - Implements hook_file_mimetype_mapping_alter().
1 invocation of hook_file_mimetype_mapping_alter()
- ExtensionMimeTypeGuesser::guessMimeType in core/
lib/ Drupal/ Core/ File/ MimeType/ ExtensionMimeTypeGuesser.php
File
-
core/
lib/ Drupal/ Core/ File/ file.api.php, line 124
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.