Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
theme system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
5 Jan 2014 at 23:10 UTC
Updated:
8 Aug 2026 at 12:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
larowlanCombine this with the theme request listener I have in #2016629: Refactor bootstrap to better utilize the kernel and it gets cleaner still, no need to init theme in bootstrap anymore!
Comment #3
larowlanComment #4
dawehnerThis should be better.
Comment #6
dawehner4: theme-2167635.patch queued for re-testing.
Comment #8
dawehnerNot sure what is going on here.
Comment #10
dawehnerThis was an interesting ride.
Initialisation gets the ThemeNegotiator injected, so also all negotiators, like the DefaultNegotiator.
That one gets the "system.theme" config file.
If the Initialisation class got initialized before the test code manually sets the default theme, the config object on DefaultNegotiator is not updated.
Comment #11
larowlanYou're going to hate me but don't we have to use American spellings? Initialization.
Needs a docblock
Can this be expanded on, as the method name doesn't immediately make sense given this comment.
Needs a short summary
Can you elaborate on the expected format of these objects?
General comment: boy the theme system could do with real objects and some interfaces (not related to this patch).
Comment #12
dawehnerThank you for the review!!
Yeah the australian way just looks wrong :p
Reworked the documentation somehow, what do you think about it? Does @see will allow enough to be used?
Your code does not really makes things clear. Why should a theme object be responsible for initialization itself, though maybe the theme engine certainly makes sense.
Comment #14
dawehnerUps.
Comment #15
dawehner14: theme_init-2167635.patch queued for re-testing.
Comment #16
dawehner14: theme_init-2167635.patch queued for re-testing.
Comment #17
dawehner14: theme_init-2167635.patch queued for re-testing.
Comment #19
sunHm. Some methods of the new class do not really belong to its responsibilities, IMHO.
For consistency with
ModuleHandler, at least the loading of themes belongs intoThemeHandler::load(), no?For the initialization methods, I actually wonder whether a standalone service is the right architectural tool? — Technically, the theme needs to be (re-)initialized for every
Request, and ideally only on-demand upon the first call into_theme()& Co.Lastly, the addition of theme assets, shouldn't that actually be a
Responseevent listener, limited to HTML responses?I think we need to rethink the proposed approach here.
Comment #20
dawehnerMy thoughts back in the days have been that it might be an somehow internal service only. You as a developer should just interact with the theme negotiator or some other wrapping
service. This service is just a nice separation of concerns.
This works theoretically if we remove the support to alter stuff in themes.
Yeah probably a kernel view subscriber, at which state we do have the fragments on which we can attach those assets.
Comment #21
sunYes, there is a separation of concerns by introducing a separate service, but we're running into the exact same + major trap as with the current_user service here:
The theme depends on the current request.
How do we ensure that the correct theme is (re-)initialized for a particular request?
In addition, the D8 [contrib] port of the removed core feature of user-specific themes enhances/replaces that dependency with a dependency on the current_user service.
That is definitely fine — the one and only reason for why
drupal_alter()includes themes is to allow themes to participate in theme related hooks.Any alter hook that is invoked before the theme layer is initialized is actually not expected to involve themes. The only reason for why themes participate currently is "KISS" — it simply would have been too much extra code/logic in a too frequently called code path to check whether themes are eligible to participate in a certain alter hook.
Various people actually raised major concerns against the (current) proposed solution of simply including themes in all alter hooks, because that apparently allows themes to even participate in
hook_query_alter()and similarly scary alter hooks that you definitely do not want to see in any theme. ;-)That sounds much more adequate!
Comment #22
dawehnerOn the longrun I would like to get rid of global $theme, $theme_key etc. and replace all those instances with a call to our theme negotiator service, see #2167619: Replace many of the global $theme/$theme_key with a call to the theme negotiator.
This kind of service would then ensure that the theme is actually initialized by asking the theme init. service. Maybe some other wrapping of the two services would be possible as well.
One important point is that we should be able to figure out whether the theme system is initialized because you might not want to boot it up if not needed, see the module handler as example.
Would that kind of architecture work for you?
What do you exactly refer to with the problem of the current_user service. Is this about a too early init, or about not being able to change the current theme?
If you have a new request, whether it is a subrequest or an actual one, the theme negotiator would not know yet about an active theme and initialize it.
Does it make sense to put that onto the assets of a HtmlPage object? Are html pages the only place which renders html with additional css?
Maybe not, as AJAX requests also add css, if needed.
Comment #23
dawehnerRerolled.
Comment #25
dawehner23: theme_init-2167635-23.patch queued for re-testing.
Comment #27
sunI wasn't sure on which of both issues to comment, so #2167619-17: Replace many of the global $theme/$theme_key with a call to the theme negotiator.
Perhaps, shall we create a new theme system meta issue? Apparently, there are a lot of fundamental architectural questions to figure out, and I'd rather like to do that before further time is spent on patches.
Comment #28
sunComment #29
dawehnerThis issue will be part of #2228093: Modernize theme initialization so this issue should probably be closed.
Comment #30
dawehnerThe other issue takes care of it.
Comment #32
quietone commentedUpdating tags per Issue tags field and Issue tags -- special tags and for issue #3565085: Drupal core issue tag cleanup.