Create a method for getting the MIME type for a file extension from a map

Created on 23 September 2024, 4 days ago

Problem/Motivation

MimeTypeGuesser is a service for guessing the mime type of a file. It is a service collector that will chain through any services tagged with 'mime_type_guesser'.

In core we only have ExtensionMimeTypeGuesser which looks at the file extension, but there are others that could be used including \Symfony\Component\Mime\FileBinaryMimeTypeGuesser and \Symfony\Component\Mime\FileinfoMimeTypeGuesser.

However, there are at least two places in core where we only want to look up the mime type based on the file extension:

  • \responsive_image_get_mime_type()
  • \Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::isApplicable()

In both these cases we create a fake file path with the extension and call \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guessMimeType($fakefile).

We should add a new method ExtensionMimeTypeGuesser::getMimeType() can just return the mapped mime type, and make it clear this is different from the logic of guessing the mime type.

Steps to reproduce

Proposed resolution

  • Add a new method ExtensionMimeTypeGuesser::getMimeType() can just return the mapped mime type.
  • Refactor existing code to use this method.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

file system

Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia kim.pepper ๐Ÿ„โ€โ™‚๏ธ๐Ÿ‡ฆ๐Ÿ‡บSydney, Australia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024