Spin off from #2392559: Remove all uses of file_stream_wrapper_get_* and file_get_stream_wrappers

Problem/Motivation

Remove all uses of file_get_mimetype

Proposed resolution

Remove
function file_get_mimetype($uri, $mapping = NULL)
with
\Drupal::service('file.mime_type.guesser')->guess($uri);

API changes

Remove all the uses of following function:

file_get_mimetype

Remaining tasks

Review patch

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue priority Normal as the patch removes usage of already deprecated functions
Prioritized changes code already marked for removal by 8.0.0

Comments

chintan.vyas’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.83 KB

Removed all uses of file_get_mimetype with \Drupal::service('file.mime_type.guesser')->guess($uri);. We need to create subtask for removing function itself.

mondrake’s picture

Status: Needs review » Needs work

Thanks @chintan.vyas!

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -446,7 +446,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'] = \Drupal::service('file.mime_type.guesser')->guess($values['favicon_path']);
       }
     }

This should be injected instead of calling \Drupal::service(). Have a look at the patch in the parent issue #2392559-37: Remove all uses of file_stream_wrapper_get_* and file_get_stream_wrappers where that's still in.

chintan.vyas’s picture

Status: Needs work » Needs review
StatusFileSize
new4.02 KB

Applied changes from parent issue's patch.

mondrake’s picture

Status: Needs review » Needs work

Just a couple of doc issues

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -38,6 +39,12 @@ class ThemeSettingsForm extends ConfigFormBase {
+   * The MIME type guesser.
+   * @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface

There should be an empty comment line between the description and the @var.

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -49,16 +56,19 @@ class ThemeSettingsForm extends ConfigFormBase {
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface module_handler

Missing $ in front of the $module_handler variable.

Can you also post an interdiff in a new patch?

chintan.vyas’s picture

Status: Needs work » Needs review
StatusFileSize
new4.03 KB
new979 bytes

Docs modifications and interdiff of changes.

mondrake’s picture

Thanks

Patch in #5 removes all usages of deprecated file_get_mimetype, and fixes two minor doc issues.

RTBC

mondrake’s picture

Issue summary: View changes

Created #2417071: Remove file_get_mimetype for function removel, added beta evaluation

mondrake’s picture

RavindraSingh’s picture

StatusFileSize
new4.62 KB

patch on #5 works fine. keeping RTBC as same

  • alexpott committed 923527b on 8.0.x
    Issue #2415757 by chintan.vyas: Remove all uses of file_get_mimetype
    
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 923527b and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

@RavindraSingh uploading an image saying that the patch applies is unnecessary on rtbc patches. The rtbc queue is retested by testbot. Also it looks like you are trying to get undeserved commit credit which is unseemly.

RavindraSingh’s picture

@alexpott, This was not my concern to get commit credits. I am aware about that up-loader can be excluded.

Thanks for not adding me in commit message.

alexpott’s picture

@RavindraSingh that's great - so if you could just post comments instead of uploading images then I have to think less when checking the automatic commit message. Also if you are adding code snippets to issues you can use http://dreditor.org - Plus if you are contributing to Drupal core join #drupal-contribute on IRC and then rather than discussing this in issue comments we can chat in in IRC - see https://www.drupal.org/irc

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.