diff --git a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php index 01e75b9..21b1d92 100644 --- a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php +++ b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapper.php @@ -891,4 +891,17 @@ public function getMimeTypeForExtension($extension) { return isset($extensions[$extension]) ? $this->mapping['mimetypes'][$extensions[$extension]] : NULL; } + /** + * {@inheritdoc} + */ + public function getExtensionsForMimeType($mimetype) { + if (!in_array($mimetype, $this->mapping['mimetypes'])) { + return []; + } + $key = array_search($mimetype, $this->mapping['mimetypes']); + $extensions = array_keys($this->mapping['extensions'], $key); + sort($extensions); + return $extensions; + } + } diff --git a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapperInterface.php b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapperInterface.php index 8618a86..1143aa5 100644 --- a/core/lib/Drupal/Core/File/MimeType/MimeTypeMapperInterface.php +++ b/core/lib/Drupal/Core/File/MimeType/MimeTypeMapperInterface.php @@ -43,4 +43,15 @@ public function getMimeTypes(); */ public function getMimeTypeForExtension($extension); + /** + * Returns the appropriate extensions for a given MIME type. + * + * @param string $mimetype + * A MIME type. + * + * @return string[] + * An array of file extensions matching the MIME type, without leading dot. + */ + public function getExtensionsForMimeType($mimetype); + }