diff --git a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php index bdb34e5..e6553b9 100644 --- a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php +++ b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php @@ -863,13 +863,6 @@ class MimeTypeMapper implements MimeTypeMapperInterface { ); /** - * Track if hook_file_mimetype_mapping_alter() has been already invoked. - * - * @var bool - */ - protected $isMappingAltered = FALSE; - - /** * The module handler. * * @var \Drupal\Core\Extension\ModuleHandlerInterface @@ -879,34 +872,30 @@ class MimeTypeMapper implements MimeTypeMapperInterface { /** * Constructs a new MimeTypeMapper. * + * Invokes hook_file_mimetype_mapping_alter() to allow modules to alter + * the mapping. + * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * + * @see hook_file_mimetype_mapping_alter() */ public function __construct(ModuleHandlerInterface $module_handler) { $this->moduleHandler = $module_handler; + $this->moduleHandler->alter('file_mimetype_mapping', $this); } /** * Returns the mapping from file extensions to appropriate MIME types. * - * Invokes hook_file_mimetype_mapping_alter() to allow modules to alter - * the mapping. - * * @return array * An array consisting of two arrays: * - mimetypes: MIME types, keyed by a unique number. * - extensions: an associative array with the MIME type key numbers as * values. The keys are file extensions, in lower case and without any * preceding dot. - * - * @see hook_file_mimetype_mapping_alter() */ protected function getMapping() { - if (!$this->isMappingAltered) { - // Allow modules to alter the default mapping. - $this->isMappingAltered = TRUE; - $this->moduleHandler->alter('file_mimetype_mapping', $this); - } return $this->mapping; } @@ -914,17 +903,13 @@ protected function getMapping() { * {@inheritdoc} */ public function addMapping($mimetype, $extension) { - // Calls ::getMapping() to make sure new mappings are added to the - // ::$mapping array that has been altered by modules already. - $this->getMapping(); - if (!in_array($mimetype, $this->mapping['mimetypes'])) { $this->mapping['mimetypes'][] = $mimetype; } $key = array_search($mimetype, $this->mapping['mimetypes']); $this->mapping['extensions'][$extension] = $key; - return TRUE; + return $this; } /** diff --git a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapperInterface.php b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapperInterface.php index 1143aa5..9b05e8c 100644 --- a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapperInterface.php +++ b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapperInterface.php @@ -19,8 +19,7 @@ * @param string $extension * The extension that should map to the passed mimetype. * - * @return bool - * Boolean TRUE if the mapping was added successfully, FALSE otherwise. + * @return $this */ public function addMapping($mimetype, $extension); diff --git a/core/modules/system/file.api.php b/core/modules/system/file.api.php index ea13843..ee8b9d2 100644 --- a/core/modules/system/file.api.php +++ b/core/modules/system/file.api.php @@ -100,7 +100,7 @@ function hook_file_url_alter(&$uri) { } /** - * Alter MIME type mappings used to determine MIME type from a file extension. + * Alter the mapping of MIME types to file extensions. * * Invoked by \Drupal\Core\File\MimeType\MimeTypeMapper::getMapping(). It * is used to allow modules to add to or modify the default mapping from diff --git a/core/modules/system/src/Tests/File/MimeTypeTest.php b/core/modules/system/src/Tests/File/MimeTypeTest.php index 1fec540..357fd77 100644 --- a/core/modules/system/src/Tests/File/MimeTypeTest.php +++ b/core/modules/system/src/Tests/File/MimeTypeTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains Drupal\system\Tests\File\MimeTypeTest. + * Contains \Drupal\system\Tests\File\MimeTypeTest. */ namespace Drupal\system\Tests\File;