Problem/Motivation

The last not-deprecated function in file.inc
There's only 4 usages in core (2 in code and 2 in tests) and a bit in contrib modules http://grep.xnddx.ru/search?text=file_build_uri

Proposed resolution

Deprecate it without replacement because it using config which is hard to inject into stream-wrappers

Remaining tasks

agree, patch, commit

User interface changes

no

API changes

deprecate file_build_uri()

Data model changes

no

Release notes snippet

no

Comments

andypost created an issue. See original summary.

kim.pepper’s picture

Status: Active » Needs review
StatusFileSize
new4.19 KB

Removed usages in core.

daffie’s picture

Status: Needs review » Needs work

The patch looks good, only the deprecation message test is missing.

daffie’s picture

Created a CR.

The patch also needs to link to the CR.

kim.pepper’s picture

Issue tags: -Needs change record +Novice

Tagging

kim.pepper’s picture

Status: Needs work » Needs review
StatusFileSize
new5 KB
new1.84 KB

Adds deprecation test and links to CR.

andypost’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice

Looks ready

berdir’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/includes/file.inc
@@ -95,8 +95,14 @@ function file_url_transform_relative($file_url) {
+  @trigger_error('file_build_uri() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0 without replacement. See https://www.drupal.org/node/3223016', E_USER_DEPRECATED);

this is linking to the issue, not the CR.

I reviewed and updated the CR a bit to clarify, that in many cases, you should either provide configuration that includes the scheme or if the path is hardcoded, you don't need to normalize it.

kim.pepper’s picture

Status: Needs work » Needs review
StatusFileSize
new5 KB
new1.97 KB

Oops! Good catch.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, back to RTBC then.

berdir’s picture

+++ b/core/modules/system/system.module
@@ -1175,7 +1175,9 @@ function system_retrieve_file($url, $destination = NULL, $managed = FALSE, $repl
   /** @var \Drupal\Core\File\FileSystemInterface $file_system */
   $file_system = \Drupal::service('file_system');
   if (!isset($destination)) {
-    $path = file_build_uri(\Drupal::service('file_system')->basename($parsed_url['path']));
+    $path = $file_system->basename($parsed_url['path']);
+    $path = \Drupal::config('system.file')->get('default_scheme') . '://' . $path;
+    $path = \Drupal::service('stream_wrapper_manager')->normalizeUri($path);
   }
   else {

FWIW, system_retrieve_file() is another thing we should deprecate, maybe with, maybe without exact replacement. It's one of those helper functions that directly display messags and can't be used with proper error handling. But that's very much a separate issue and might already have one.

kim.pepper’s picture

Status: Reviewed & tested by the community » Needs work
berdir’s picture

Status: Needs work » Reviewed & tested by the community

Accidental status change I asusme?

kim.pepper’s picture

Yes. My mistake.

  • catch committed d6e4a29 on 9.3.x
    Issue #3223016 by kim.pepper, Berdir, andypost, daffie: Deprecate...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Good idea to just remove, doesn't even meet the rule of three in core.

Committed d6e4a29 and pushed to 9.3.x. Thanks!

andypost’s picture

The issue only remaining left! Great job

Status: Fixed » Closed (fixed)

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