Symfony 5 replaces \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface with \Symfony\Component\Mime\MimeTypeGuesserInterface. As a result, the mime type guesser service has added a ::guessMimeType() method. This should be called instead of ::guess(), which is deprecated and will be removed in Drupal 10.
Modules that replace the file.mime_type.guesser or file.mime_type.guesser.extension service should implement the new ::guessMimeType() method.
Note that changing calls to ::guess() to ::guessMimeType() directly may introduce incompatibilities both with Drupal 9.0.x and lower, and with any contrib or custom code that overrides the service. Therefore, you may wish to check the instance of the service and call the different methods conditionally.
For example:
- $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['filename']);
+ $guesser = \Drupal::service('file.mime_type.guesser');
+ if ($guesser instanceof \Symfony\Component\Mime\MimeTypeGuesserInterface) {
+ $values['filemime'] = $guesser->guessMimeType($values['filename']);
+ }
+ else {
+ $values['filemime'] = $guesser->guess($values['filename']);
+ @trigger_error('\Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface is deprecated in drupal:9.1.0 and will be removed in drupal:10.0.0, implement \Symfony\Component\Mime\MimeTypeGuesserInterface instead. See https://www.drupal.org/node/3133341', E_USER_DEPRECATED);
+ }