Closed (outdated)
Project:
Drupal core
Version:
main
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
9 Aug 2019 at 00:03 UTC
Updated:
29 Mar 2026 at 13:38 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
kim.pepperComment #3
kim.pepperMoved to locale.module and deprecated system_check_directory(). Also added a deprecation test.
Comment #4
kim.pepperComment #5
andypostNice clean-up
Comment #6
andypostbtw not sure that new "API" method in locale makes sense, usage in contrib is not big http://grep.xnddx.ru/search?text=system_check_directory
Comment #7
kim.pepper@andypost do you suggest making it private? e.g. _locale_form_check_directory()
Comment #8
larowlanI was originally thinking we could just move it to an .inc file and load that in locale module, to get it out of the hotpath.
We should be doing the same here, putting it in locale.module also means its in the hotpath for every page.
Comment #9
larowlanactually, could we use a static method on a class to make it autoloaded on demand?
Comment #10
kim.pepperOK. Something like this...
Comment #11
kim.pepperAs there are a bunch of dependencies, it would be better to make this a service.
Would doing something like
'#after_build' => [[\Drupal::service('locale.settings.helper'), 'checkDirectory']],be acceptable?Comment #12
larowlanMy 2c
Keep the static method, but make it do
\Drupal::classResolver()->getInstanceFromDefinition(self::class)->{aProtectedMethodThatIsntStatic}and move the logic into a protected method that isn't staticComment #13
kim.pepperBut ClassResolver will just do
$instance = new $definition();which means you can't inject the deps?Comment #14
larowlanIf your class implements ContainerInjectionInterface, it will call the ::create method and pass the container
Comment #15
kim.pepperThat's seems like a few additional steps of indirection. How is that better than just \Drupal::service()? (not even sure that works 🤔)
Comment #16
larowlanusing \Drupal::service means its in the container for all requests, which it doesn't need to be
Comment #17
larowlanthere's no harm in keeping it static fwiw
Comment #18
kim.pepperOK here's a patch that uses the above approach.
Comment #19
berdirJust some quick thoughts:
#6 shows that is not used *often*, but it is used a few times and there are likely quite a few more use cases that could use it, they probably just don't know about it. Given that it's autoloaded now, any harm in putting it somewhere outside of locale module? maybe Drupal\Core\Form, given how tightly integrated into the form system it is.
The "its loaded on every request." argument feels like micro-optimization, there's nowway that the existence of a 30loc function is in any way relevant for performance. The bigger argument is that having it has a service directly would get mean that we'd have to serialize the object and its dependencies as part of the form for the callback definition, that's considerably more overhead than having a function or service defined. Thought about a trait, would have the advantage that you can just define it as '::checkDirectory', but that requires each form using it to inject the necessary dependencies. So the approach in the patch, although a bit uncommon, seems like an interesting solution, maybe we could document how it's supposed to be used on the method, specifically if we make it an actual API?
Comment #20
kim.pepperThanks for the review @Berdir!
Moved the helper to \Drupal\Core\Form\SettingsFormHelper and added a comment about it being used as a #after_build callback.
Comment #21
kim.pepperComment #22
andypostAs usage shows it's used by form element to ensure that directory exists and writable (puts htaccess?)
So probably better create special element class for that?
Comment #24
volegerReplace deprecated code.
Comment #31
smustgrave commentedRerolled for 10.1
Comment #33
smustgrave commentedComment #34
kim.pepperWe seem to have dropped the deprecation test.
Comment #36
smustgrave commentedWhat file should that go to? The file SystemFunctionsLegacyTest is deleted
Comment #37
kim.pepperIt's ok to just create a new legacy test. I've added one here.
Comment #38
smustgrave commentedMakes sense! Can I mark RTBC
Comment #39
andypostI'd want to rtbc but naming sounds weird, form helper class named as Settings*
No idea ATM for better name but I bet it will not pass commiters
Comment #40
smustgrave commentedThinking just FormHelper?
Comment #41
andypostmaybe instead of helper use a ElementFileSystem
Comment #42
andypostOTOH there's only 8 usages in contrib so probably better to inline it into Locale module and deprecate without replacement
http://codcontrib.hank.vps-private.net/search?text=system_check_director...
Updated IS
Comment #43
smustgrave commentedNot sure I follow
Or
Comment #44
smustgrave commentedComment #45
smustgrave commentedper #43
Comment #47
smustgrave commentedBelieve this is still valid.
Comment #49
volegerRerolled in MR. Please leave review comments in MR.
Comment #50
smustgrave commentedSmall comment on MR
Looking at the CR, believe it should be fine but personally I'm big fan of before/after snippets.
Super close and will keep an eye out for this one.
If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!
Comment #51
volegerAddressed review comments and updated CR
Comment #52
smustgrave commentedThanks feedback appears to be addressed
Comment #53
catchOne comment on the MR.
Comment #54
volegerIntroduced logger channel as a dependency
Comment #55
nicxvan commentedA bunch of failures looks like a service is wrong.
Comment #56
berdirThe reason that only locale still uses this function is that we moved configuration of private/public/tmp stream wrappers to Settings in settings.php.
What if we do the same instead with this locale setting? Then we don't need any replacements.
(I had some concerns about removing as there are a handful of modules using this based on code search. But only 2 of those have a release that works on a supported core version, l10n_server and library_manager) and those don't seem to use it in current versions. So should be OK).
Comment #57
kim.pepperThat sounds great!
Comment #59
nicxvan commentedThank you everyone for the great direction here.
I think we should postpone this even if it's older since the .module cleanup initiative is grouping these cleanup efforts to reduce conflict and churn.
I'll be sure to apply credit here before closing it out if we do go that direction.
There are only a few remaining functions and they are all relatively simple so we should just take care of all of them at once.
Comment #60
berdirI created #3571593: Deprecate translation.path config in favor of settings, whether we deprecate this function here or in the other issue, that non-trivial but also not crazy-complex issue will make it trivial.
Comment #61
kim.pepperComment #63
nicxvan commentedyeah maybe we postpone this on that one for now, and we address it there or here, I'll work on the other functions in the other issue.
Comment #64
nod_better search link: system_check_directory, i see only 2 contrib use that looks legit
Comment #65
nicxvan commentedI think the other one is very close.
I took a pass at credit to prepare.
Comment #66
nicxvan commentedComment #67
nicxvan commentedThank you everyone! The other one landed so this is now outdated, I already applied credit in 65.