Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We want to deprecated procedural functions in file.inc and replace with methods on FileSystem or StreamWrapperManager.
file_default_scheme() just wraps \Drupal::config('system.file')->get('default_scheme'), and porting it over just creates another API we need to maintain.
Also, we are calling file_default_scheme() in a load of tests, where we really only need 'public://'
Proposed resolution
- Replace usages of file_default_scheme() with \Drupal::config('system.file')->get('default_scheme')
- Replace usages of file_default_scheme() in tests with 'public://'
Remaining tasks
None.
User interface changes
None.
API changes
file_default_scheme() is deprecated.
Data model changes
None.
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#21 | 3049021-followup-21.patch | 869 bytes | Pancho |
#13 | 3049021-8.patch | 20.57 KB | kim.pepper |
#8 | 3049021-8.patch | 20.57 KB | kim.pepper |
#7 | 3049021-7.patch | 20.6 KB | kim.pepper |
#7 | 3049021-7-interdiff.txt | 2.03 KB | kim.pepper |
Comments
Comment #2
kim.pepperInitial patch.
Comment #3
kim.pepperFixes copy/paste error.
Comment #4
BerdirAs discussed in slack, I would actually suggest to update all usages in tests that are not specifically testing the configurable default to just hardcode public, we *know* that's the value it has and we have dozens if not hundreds of hardcoded public:// references already in tests. That will also better show how common it really is to use that configuration (and hopefully that it is indeed OK to just access the configuration).
And we also need a legacy test I think.
Comment #5
kim.pepperThanks for the review @Berdir.
Comment #6
Berdirthis is the old deprecated base test, not sure if we should touch that one at all..
this *could* maybe be a problem as it is a base class, so subclasses might rely on it, we'll see.
the docblock here still mentiones the function, with todos to convert it to a service.
Also, we could actually deprecate this function instead of updating it, call \Drupal::config() directly and mock it through the container?
aww, this will conflict with the RTBC drupal_unlink() issue, so will hold back on RTBC until that one is in. Not sure if updating that already now will merge it easier to rebase or not.
this looks completely bogus, which it was before as well, but I don't think this is what it should do.
Comment #7
kim.pepperComment #8
kim.pepperRe-roll after #3021434: Properly deprecate drupal_unlink()
Comment #9
kim.pepperComment #10
Berdir> I think this is pretty tricky to try and mock \Drupal::config() here.
Should be possible by providing a mock through a container like other unit tests, but yeah, this is out of scope here I think.
> Not sure what else to do here except replace 'public/' with 'public://'
Yeah, that's what I meant. It does test a non-existing file, but I think that's what it should have been and feels like a more realistic test than trying to delete DRUPAL_ROOT/public/...
Looks good to me I think, lets see what the committers think about this suggestion.
Maybe the issue summary could be improved a bit and e.g. point out that we removed the configurability from a lot of tests where we just know that it is public://. I quick search shows around 450 existing usages of "'public://" in tests, so these are already the exception.
Comment #11
kim.pepperComment #13
kim.pepperNot exactly sure what the fail was, so re-rolling #8.
Comment #14
BerdirRandom fail maybe, saw a few random build successful problems recently.
Comment #16
kim.pepperRandom test fails.
Comment #17
larowlanissue credits
Comment #18
larowlanCommitted 31a5cba and pushed to 8.8.x. Thanks!
published change record
Comment #21
PanchoThink we need a followup here:
It's supposed to be: https://www.drupal.org/node/3049030 instead.
Comment #22
kim.pepper@Pancho Thanks for picking this up. However, this issue is closed. I created #3058839: Incorrect @see link in file_default_scheme() deprecation if you want to post your patch there.