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

Comments

dawehner created an issue. See original summary.

rashid_786’s picture

Assigned: Unassigned » rashid_786
rashid_786’s picture

Assigned: rashid_786 » Unassigned
Status: Active » Needs review
StatusFileSize
new1.36 KB
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Cool, thank you!

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x, thanks!

  • catch committed d0daeee on 8.1.x
    Issue #2638150 by rashid_786, dawehner: Move...
dawehner’s picture

Version: 8.1.x-dev » 8.0.x-dev
Status: Fixed » Reviewed & tested by the community

Move to 8.0.x as well

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: 2638150-2.patch, failed testing.

snehi’s picture

Status: Needs work » Reviewed & tested by the community

Making again it to RTBC

xjm’s picture

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

I 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() to system.module and 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?

dawehner’s picture

Hei, 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.

I 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().

Its hard to imagine that this is not safe for a patch release to be honest. Let's have a early bootstrap code:

  public function preHandle(Request $request) {

    $this->loadLegacyIncludes(); // This loads theme.inc

    // Load all enabled modules.
    $this->container->get('module_handler')->loadAll();

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 in theme.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.

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?

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.

xjm’s picture

All 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.

dawehner’s picture

The 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.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new2.54 KB

So something like this.

catch’s picture

We 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.

dawehner’s picture

From 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.

Status: Needs review » Needs work

The last submitted patch, 14: 2638150-14.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new583 bytes
new2.87 KB

Sorry 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.

dawehner’s picture

Thank you @joelpittet

lauriii’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/system.module
@@ -1066,13 +1067,7 @@ function system_rebuild_module_data() {
 function _system_default_theme_features() {

Lets mark it also deprecated

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new3.06 KB
new613 bytes

Sure.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Removes 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)

snehi’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/system.module
@@ -1065,6 +1065,9 @@ function system_rebuild_module_data() {
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.

Why 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.

joelpittet’s picture

@snehi feel free to remove the -dev. It's probably not needed but there are 33 instances in core of it's use.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new3.06 KB
new593 bytes

Fixed that, but yeah I could not care less.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: 2638150-25.patch, failed testing.

dawehner’s picture

Status: Needs work » Reviewed & tested by the community

.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

@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?

dawehner’s picture

Mh, 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.

alexpott’s picture

So if we had a ThemeFeatures thing should be ensure that it can also handle doing the theme_get_setting work?

dawehner’s picture

StatusFileSize
new4.27 KB
new2.98 KB

Its a bit sad that this adds a dependency from extension level code for theme level code. Well adding, it rather makes it explicit.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Yay, explicitly sad patch!

dawehner’s picture

StatusFileSize
new4.38 KB
new977 bytes

Nope

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Hmmm doesn't #32 prove we're missing test coverage?

The last submitted patch, 32: 2638150-32.patch, failed testing.

lauriii’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs tests

Patch #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.

alexpott’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Needs work

I think this fix needs to go into 8.1.x first and unfortunately the patch does not apply because the branches have diverged.

dawehner’s picture

StatusFileSize
new3.57 KB

Yeah 8.1.x indeed already moved along, see #5

dawehner’s picture

Status: Needs work » Needs review

.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Let's fix this.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

I'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 be ThemeSettings - 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?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

StatusFileSize
new4.22 KB
new2.66 KB

There we go.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @dawehner and @alexpott, makes sense to keep this in the ThemeSettings class.

star-szr’s picture

Status: Reviewed & tested by the community » Needs work

I think we need to remove the ThemeFeatures class and use in ThemeHandler unless I'm missing something.

  1. +++ b/core/includes/theme.inc
    @@ -96,16 +98,13 @@ function theme_get_registry($complete = TRUE) {
    + * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0.
    + *   Use \Drupal\Core\Theme\ThemeSettings::defaults() instead.
    

    Don't we want this to say deprecated in 8.2.x?

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.35 KB
new3.13 KB

Nice spotting that @Cottser, thanks I've just cleaned-up the items from #46

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 47: move-2638150-47.patch, failed testing.

  • catch committed d0daeee on 8.3.x
    Issue #2638150 by rashid_786, dawehner: Move...

  • catch committed d0daeee on 8.3.x
    Issue #2638150 by rashid_786, dawehner: Move...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community

Not sure what happened to this @catch, the commits look like some kind of mistake?

catch’s picture

Status: Reviewed & tested by the community » Fixed

No I think I just failed to update the issue to fixed. Doing that now!

alexpott’s picture

Status: Fixed » Needs review

So 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.

catch’s picture

Version: 8.3.x-dev » 8.1.x-dev
Status: Needs review » Closed (fixed)

OK 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.