Problem/Motivation
theme_get_settings() is used in places like the maintenance / error .
This function calls out to _system_default_theme_features which lives in system.module,
so we have some brittleness here, in case some early bootstrap fails.
Proposed resolution
Move this function into theme.inc
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | move-2638150-47.patch | 3.13 KB | joelpittet |
| #47 | interdiff.txt | 1.35 KB | joelpittet |
| #44 | interdiff.txt | 2.66 KB | dawehner |
| #44 | 2638150-44.patch | 4.22 KB | dawehner |
| #39 | 2638150-39.patch | 3.57 KB | dawehner |
Comments
Comment #2
rashid_786 commentedComment #3
rashid_786 commentedComment #4
dawehnerCool, thank you!
Comment #5
catchCommitted/pushed to 8.1.x, thanks!
Comment #7
dawehnerMove to 8.0.x as well
Comment #9
snehi commentedMaking again it to RTBC
Comment #10
xjmI don't think we should necessarily move this to a different file in 8.0.x in case some code/test/etc. was relying on it being available with module_load_include(). This is a good example of something that is an internal change that is safe for a minor, but might cause some disruption that we should avoid for a patch release.
I originally was going to just mark this back to fixed against 8.1.x, but the point about brittleness during bootstrap made me reconsider. @dawehner, can you clarify a bit about how you might encounter it?
Maybe a solution for 8.0.x would be to add a
if !function_exists()tosystem.moduleand define the function conditionally there.Also, for 8.1.x, isn't the function namespaced incorrectly now? So alternately, we could deprecate
_system_default_theme_features()and make it call a new_theme_default_features()or such in 8.1.x?@dawehner, thoughts?
Comment #11
dawehnerHei, so sadly I haven't been part of resolving of the actual error on production so this will be a bit vague, like for example I haven't seen any backtrace.
Fact is, the production system went down and for example this error message appeared.
Following down the possible call paths, together with another error message,
this means we had a broken container just containing the services from core.services.yml at some point
Anyway, this call to undefined function call lead into hiding of an error message behind the scenes, as the maintenance page rendering (for some exception/ error) is broken under this circumstances. I opened up this issue in order to reduce that level of problem, which allows you to see the actual brittleness of the system.
Its hard to imagine that this is not safe for a patch release to be honest. Let's have a early bootstrap code:
So on a regular code path, theme.inc will be included before any module files, this is for sure. This is an internal function so its never supposed to be called from anywhere,
beside its one usecase, which is
theme_get_settings(), which is intheme.inc, so in regular usages, we load this function now with theme.inc, so its safe.The only usecases so where this could break are custom scripts which don't use the kernel to initialize Drupal, which is let's say, really an obscure usecaes. Actually I would have a lot of respect for them to mock the entire bootstrapping of Drupal to call a method which returns always the same array with 4 elements.
When we talk about risk vs. profit, I would totally commit it to 8.0.x, because the risk of a broken production system not showing what actually is broken is much more problematic vs. a theoretical function call in some obscure code.
Well, if you would ask me in an ideal world I would just inline this function, there is no point for it. Otherwise yes, maybe a better prefix would be nice.
So yeah we would also fix the problem in 8.0.x, by inlining this array with 5 elements and drop the function call to it entirely.
Comment #12
xjmAll great points.
So how about we instead mark the function as deprecated, and inline the single use of it in theme_get_setting() with a comment that references ThemeHandler::$defaultFeatures?
Come to think of it, I wonder why there is not a getter for that property on the theme handler to begin with. The theme handler service is obviously available in theme_get_setting(). So maybe we could revert the earlier 8.1.x patch, commit the deprecation to both 8.0.x and 8.1.x so that both branches are more consistent, and inline the call in 8.0.x but move it to a getter on the theme handler in 8.1.x.
Comment #13
dawehnerThe only thing I'm wondering, is theme_get_setting() called in a context of a broken container, so the service might not be available?
Oh well actually theme_get_setting() calls out to it, so nevermind.
Well obiously, we cannot change the ThemeHandlerInterface at that point, so the one thing which would work is a public static property.
Comment #14
dawehnerSo something like this.
Comment #15
catchWe could add a new interface and a new service, deprecating the old interface and service, or something like that.
Another way would be theme_get_setting() moves to a class, then move the property to a trait.
All of this feels like follow-up. I'd be fine with reverting the 8.1.x patch and inlining for now.
Comment #16
dawehnerFrom an interface point of view, this really doesn't belong onto the theme handler. The theme handler is not a dumping ground for theme related functions.
Comment #18
joelpittetSorry haven't read much, just spotted this issue and don't know the best solution around the architecture move, just passing through and thought I might fix #14.
Comment #19
dawehnerThank you @joelpittet
Comment #20
lauriiiLets mark it also deprecated
Comment #21
dawehnerSure.
Comment #22
joelpittetRemoves some duplication, provides minor direction to take in 9.x with @todo and deprecates the use of a private global function (which is private by _ convention)
Comment #23
snehi commentedWhy dev stated here, can't only 8.0.x will work here.
I am pointing out because i haven't seen this in any documentation.
Comment #24
joelpittet@snehi feel free to remove the -dev. It's probably not needed but there are 33 instances in core of it's use.
Comment #25
dawehnerFixed that, but yeah I could not care less.
Comment #26
lauriiiComment #28
dawehner.
Comment #29
alexpott@dawehner so if the default features do not belong on ThemeHandler where do they belong and can we move them there rather than just making a public static property? Also can't a public static property be changed?
Comment #30
dawehnerMh, I would have said
ThemeFeatures::$default|getDefault()would be all what is needed.If we are crazy about the alterability we could even implement
__set, not sure though whether I care that much.Comment #31
alexpottSo if we had a ThemeFeatures thing should be ensure that it can also handle doing the theme_get_setting work?
Comment #32
dawehnerIts a bit sad that this adds a dependency from extension level code for theme level code. Well adding, it rather makes it explicit.
Comment #33
joelpittetYay, explicitly sad patch!
Comment #34
dawehnerNope
Comment #35
alexpottHmmm doesn't #32 prove we're missing test coverage?
Comment #37
lauriiiPatch #32 has multiple test failures which proves it has some test coverage. @dawehner mentioned that there was problem with the test bot during that time which might have caused the positive false test result.
Comment #38
alexpottI think this fix needs to go into 8.1.x first and unfortunately the patch does not apply because the branches have diverged.
Comment #39
dawehnerYeah 8.1.x indeed already moved along, see #5
Comment #40
dawehner.
Comment #41
jibranLet's fix this.
Comment #42
alexpottI've been thinking about the longer term aim of trying to refactor
theme_get_settings(). One of the obvious places to move all of that code would beThemeSettings- and actually I think that class would make a good home for this static method -ThemeSettings::defaultFeatures(). One less class to load. @dawehner what do you think?Comment #44
dawehnerThere we go.
Comment #45
joelpittetThanks @dawehner and @alexpott, makes sense to keep this in the ThemeSettings class.
Comment #46
star-szrI think we need to remove the ThemeFeatures class and
usein ThemeHandler unless I'm missing something.Don't we want this to say deprecated in 8.2.x?
Comment #47
joelpittetNice spotting that @Cottser, thanks I've just cleaned-up the items from #46
Comment #52
joelpittetNot sure what happened to this @catch, the commits look like some kind of mistake?
Comment #53
catchNo I think I just failed to update the issue to fixed. Doing that now!
Comment #54
alexpottSo there was a patch committed on #5 then the issue was re-opened for no good reason and work continued on a slightly different solution. The recent commit messages occurred when the new branch was opened. So the patch in #47 is for 8.3.x.
Comment #55
catchOK that makes more sense, but we should have had a new issue 50 comments ago, so moving back to closed (fixed). Opened #2804453: _system_default_theme_features() refactoring.