Replace all instances of "file_stream_wrapper_get_instance_by_uri()" in core with "\Drupal::service('stream_wrapper_manager')->getViaUri()" or the same call on an injected service.

The function itself should not be removed yet.

Comments

kallehauge’s picture

kallehauge’s picture

Issue summary: View changes
rpayanm’s picture

Title: Replace all instances of "file_stream_wrapper_get_instance_by_uri()" in core » Remove usage of file_stream_wrapper_get_instance_by_uri()
Status: Needs work » Needs review
Issue tags: +Novice, +@deprecated
StatusFileSize
new3.49 KB

@kallehauge you must change the Status to "Needs review" to test the patch.

ianthomas_uk’s picture

Issue summary: View changes
Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php
    @@ -37,7 +37,7 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface {
    -    if ($wrapper = file_stream_wrapper_get_instance_by_uri($path)) {
    +    if ($wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($path)) {
    

    OO code - this should be injected

  2. +++ b/core/modules/image/src/Entity/ImageStyle.php
    @@ -221,7 +221,7 @@ public function buildUrl($path, $clean_urls = NULL) {
    -      $directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath();
    +      $directory_path = \Drupal::service('stream_wrapper_manager')->getViaUri($uri)->getDirectoryPath();
    

    OO code - this should be injected

Looks good other than the lack of dependency injection. It is correct to not remove the function itself at this stage, I've updated the issue summary to clarify.

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new4.41 KB
new6.35 KB
jeroent’s picture

Is the create method in MimeTypeGuesser really necessary?

We already pass the streamWrapperManager in core.services.yml so I think that's enough.

Status: Needs review » Needs work

The last submitted patch, 5: 2363717-5.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new750 bytes
new6.16 KB

Umm... thank you :)

Status: Needs review » Needs work

The last submitted patch, 8: 2363717-8.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Needs review
StatusFileSize
new909 bytes
new5.74 KB

#8 didn't remove the interface, just the method being implemented. This will need a change record.

Status: Needs review » Needs work

The last submitted patch, 10: file_stream_wrapper_get_instance_by_uri-2363717-10.patch, failed testing.

ianthomas_uk’s picture

ianthomas_uk’s picture

Issue summary: View changes
Issue tags: +Needs change record
ianthomas_uk’s picture