Problem/Motivation
After #2669074: Convert file_create_url() & file_url_transform_relative() to service, deprecate it fix, FileUriFormatter is not returning absolute URL.
As per the change record which states:
- The method generateString() which creates a root-relative web-accessible URL string
- The method generateAbsoluteString() which creates an absolute web-accessible URL string;
file_create_url() is supposed to be changed to \Drupal::service('file_url_generator')->generateAbsoluteString($uri)
Instead of that, it is updated with $this->fileUrlGenerator->generateString($uri)
That causes the regression.
Steps to reproduce
Check the FileUriFormatter before #2669074: Convert file_create_url() & file_url_transform_relative() to service, deprecate it and after the fix.
Proposed resolution
Fix the incorrect change and replace with correct method.
Remaining tasks
N/A
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Original report by @joakland
Following upgrade to Drupal 9.3.0, checking the "Display the file download URI" for a "File: URI" field in Views no longer displays an absolute path; now it displays a relative path.
Issue fork drupal-3253897
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3253897-regression-display-the
changes, plain diff MR !12265
Comments
Comment #2
lendudeQuick little git-blame points to #2669074: Convert file_create_url() & file_url_transform_relative() to service, deprecate it, so that would not make this due to a change in Views but on the field formatter.
Comment #8
mohit_aghera commentedThis certainly seems a regression because of issue #2669074: Convert file_create_url() & file_url_transform_relative() to service, deprecate it
As per the change record
file_create_url()<code> is supposed to be moved to <code>\Drupal::service('file_url_generator')->generateAbsoluteString($uri)Instead of that, it is updated with
$this->fileUrlGenerator->generateString($uri)That sounds the root cause of the regression.
Probably this wasn't caught becuase we don't have test coverage for this one.
I've raised a PR with the fix and working on test coverage.
Comment #9
mohit_aghera commentedComment #10
smustgrave commentedCan the issue summary be updated to include the issue this was added? May have been done on purpose. 4 years makes me wonder if it was a regression
Comment #11
mohit_aghera commentedI checked the gigantic thread of the issue #2669074: Convert file_create_url() & file_url_transform_relative() to service, deprecate it
The changes approximately starts from comment 83 https://www.drupal.org/project/drupal/issues/2669074#comment-13003933
I don't see any specific discussion of switching
generateStringinstead ofgenerateAbsoluteStringto FileUriFormatter.I believe this issue might not have caught till date because there might be very few sites who are using URI formatter.
I've updated issue summary as well. Happy to close if required.
Comment #12
mohit_aghera commentedComment #13
smustgrave commentedApologize I've had this tab open for like 3 days and keep getting distracted
Summary looks good now thanks for that!
Ran the test-only feature and got
Wasn't 100% how to manually test but use of generateAbsoluteString() per the CR
Comment #15
cassioalmeida commentedHi everyone,
I created a patch from MR and applied it to 10.5.1. Worked perfectly!
Comment #16
oily commentedTest-only test output:
Comment #17
oily commentedComment #18
oily commentedComment #19
xjmFor #16, it's actually usually preferred to document the output of the failing test for the test-only in the job in a code tag, like so:
It's not sufficient that it fails; it needs to fail in the right way and then we document that.
But that has already been done for this issue, so there is no need to repeat it after RTBC. 🙂
I guess you were trying to say your rebase had the same test-only fail as in the previous comment?
Comment #20
oily commentedRE: #19
Actually, i think that makes sense. Edited #16. When I read #13 for some reason I got the impression @smustgrave was reporting a problem with the test.
Comment #21
oily commentedComment #22
oily commentedUpdated IS.
Comment #26
catchCommitted/pushed to 11.x, cherry-picked to 11.2.x and 10.6.x thanks!