diff --git a/core/includes/file.inc b/core/includes/file.inc index b38cf14..79519ff 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -1152,32 +1152,6 @@ function file_upload_max_size() { } /** - * Determines an Internet Media Type or MIME type from a filename. - * - * @param $uri - * A string containing the URI, path, or filename. - * @param $mapping - * An optional map of extensions to their mimetypes, in the form: - * - 'mimetypes': a list of mimetypes, keyed by an identifier, - * - 'extensions': the mapping itself, an associative array in which the key - * is the extension (lowercase) and the value is the mimetype identifier. - * - * @return - * The internet media type registered for the extension or - * application/octet-stream for unknown extensions. - * - * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. Calls are - * passed on to a new file.mime_type.guesser service, and the $mapping - * parameter is ignored. Use - * \Drupal::service('file.mime_type.guesser')->guess($uri). - * - * @see \Drupal\Core\File\MimeType\ExtensionMimeTypeGuesser::guess() - */ -function file_get_mimetype($uri, $mapping = NULL) { - return \Drupal::service('file.mime_type.guesser')->guess($uri); -} - -/** * Sets the permissions on a file or directory. * * This function will use the file_chmod_directory and diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 1d78fb3..4a71b0f 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -758,7 +758,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination 'uri' => $file_info->getRealPath(), 'filesize' => $file_info->getSize(), ); - $values['filemime'] = file_get_mimetype($values['filename']); + $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['uri']); $file = entity_create('file', $values); $extensions = ''; diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php index b21a182..7f89508 100644 --- a/core/modules/file/src/Entity/File.php +++ b/core/modules/file/src/Entity/File.php @@ -195,7 +195,7 @@ public static function preCreate(EntityStorageInterface $storage, array &$values // Automatically detect filemime if not set. if (!isset($values['filemime']) && isset($values['uri'])) { - $values['filemime'] = file_get_mimetype($values['uri']); + $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['uri']); } } diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index 44649d2..fa7a414 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -11,6 +11,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\StreamWrapper\PublicStream; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\ConfigFactoryInterface; @@ -30,17 +31,27 @@ class ThemeSettingsForm extends ConfigFormBase { protected $moduleHandler; /** + * The mime type guesser. + * + * @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface + */ + protected $mimeTypeGuesser; + + /** * Constructs a ThemeSettingsForm object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. * @param \Drupal\Core\Extension\ModuleHandlerInterface * The module handler instance to use. + * @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser + * The mime type guesser. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, MimeTypeGuesserInterface $mime_type_guesser) { parent::__construct($config_factory); $this->moduleHandler = $module_handler; + $this->mimeTypeGuesser = $mime_type_guesser; } /** @@ -49,7 +60,8 @@ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandle public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('file.mime_type.guesser') ); } @@ -414,7 +426,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } if (empty($values['default_favicon']) && !empty($values['favicon_path'])) { - $values['favicon_mimetype'] = file_get_mimetype($values['favicon_path']); + $values['favicon_mimetype'] = $this->mimeTypeGuesser->guess($values['favicon_path']); } }