Problem/Motivation
With #1921558: Convert file_get_mimetype() to use Symfony MimeTypeGuessers, the function file_mimetype_mapping()
was removed. The mapping was placed as a protected property of the ExtensionMimeTypeGuesser
class, as its main purpose was for the guesser to use it. But there are cases when the mapping, or just the list of MIME types, should be used in itself, outside the context of guessing. For instance, a form in the File entity module should present known MIME types for the user.
Proposed resolution
Move the default mapping to a new service and class, Drupal\Core\File\MimeType\MimeTypeMapper
, with getter/setter methods.
Introduce an alterMapping()
method which invokes the mimetype
alter hook upon service instantiation to allow modules to play with MIME type<->extension mapping.
Change the ExtensionMimeTypeGuesser
class to use the new mapper; deprecate its ::setMapping
method.
Deprecate the file_mimetype_mapping
alter hook.
Add tests.
Add tests.
Remaining tasks
Commit
User interface changes
None
API changes
A new service file.mime_type.mapper
.
Beta phase evaluation
Issue category | Bug because functionality in previous version is now missing |
---|---|
Issue priority | Major because it is a small regression. In D7 one could access the mapping out of the context of guessing, and could eg get a list of all known mimetypes . After #1921558: Convert file_get_mimetype() to use Symfony MimeTypeGuessers its impossible without extending the class, because the mapping is a protected property |
Disruption |
None, a BC layer covers the case of custom/contrib classes extending from ExtensionMimeTypeGuesser .
|