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 load as few as code as possible on requests, unless needed.
Currently the ThemeHandler has quite a lot of dependencies:
public function __construct($root, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilderInterface $route_builder = NULL, ExtensionDiscovery $extension_discovery = NULL) {
Another problem is that the module_installer exists, but the theme_handler is still responsible for installing
Proposed resolution
Move the installation code of themes into its separate entity, called ThemeInstaller.
That itself improves the performance a bit.
As BC layer we can keep ThemeHandler::install() but just call out to the other code.
Remaining tasks
User interface changes
API changes
- New service called theme_installer
- theme_handler->install() => theme_install->install()
- theme_handler->uninstall() => theme_install->uninstall()
Beta phase evaluation
Issue category | Task, because it improves performance a bit. |
---|---|
Issue priority | Normal, as the impact is not that high |
Disruption | The amount of people installing / uninstalling a theme in core is not high, but we have the advantage of having to initiate less themes. |
Comment | File | Size | Author |
---|---|---|---|
#24 | 2465887-24.patch | 38.45 KB | tim.plunkett |
#21 | interdiff.txt | 4.17 KB | dawehner |
#21 | 2465887-21.patch | 38.55 KB | dawehner |
#14 | interdiff.txt | 965 bytes | dawehner |
#14 | 2465887-14.patch | 38.26 KB | dawehner |
Comments
Comment #1
dawehnerInitial quick try.
Comment #2
dawehner.
Comment #4
dawehnerDoh.
Comment #6
dawehnerSome fixes.
Comment #8
dawehnerLet's fix the failure.
Comment #10
jibranCan we use setter injection to avoid circular dependency and remove \Drupal use? Just like we did in #2448847: [regression] Themes unable to implement hook_theme_registry_alter().
Comment #11
amateescu CreditAttribution: amateescu for Drupal Association commentedThe patch looks great to me, it should improve the performance a bit because the object that we're using more often, the theme handler, is quite a bit lighter in dependencies.
Also rerolled the patch, added a docblock to the new interface and removed the methods from ThemeHandlerInterface (that's why also ThemeHandler implements ThemeInstallerInterface now, right?)
Just a small question before RTBC-ing this:
Do you think we should put a comment above this line to say that not doing any kind of dependency injection here is because it would cause a circular dependency and it would also remove all the benefits of this patch.
Comment #12
dawehnerThis itself is a great idea. Thank you!
Maybe we could ask whether we could remove the BC layer entirely.
Comment #13
dawehnerAdding some points after discussing the issue with @xjm in montpellier.
Comment #14
dawehnerWell, its not only circular dependency, but its just an old BC layer we are dealing with. Adapted the comment for that.
Comment #15
amateescu CreditAttribution: amateescu for Drupal Association commentedThanks for the comment, it should be helpful if anyone stumbles upon this code. Looks great now :)
Comment #16
jibranShould anyone care to comment on #10?
Comment #17
dawehnerI thoguht it got answered with the fact that we have a BC layer here.
Comment #18
dawehnerI thoguht it got answered with the fact that we have a BC layer here.
Comment #19
alexpottThis makes sense - it brings us inline with ModuleHandler and we're not breaking BC. It would be nice to know the impact of doing this. But I do appreciate that it part of disentangling the dependency knots in the container.
I don't think we should remove them from the interface I think we should add an @deprecated D9 statement and an @see to the new service.
Comment #20
alexpottNo class doc.
Comment #21
dawehnerFair point, did those.
Comment #22
msonnabaum CreditAttribution: msonnabaum commentedStill see parts of ThemeHandler that look rough, but nothing in scope for this issue. This patch is a solid code improvement. Looks great!
Comment #24
tim.plunkettNo changes, just git apply -3
Comment #25
tim.plunkettMeant to put it back
Comment #26
dawehnerThank you @msonnabaum I kinda might try to ping you more in the future!
Comment #27
alexpottNot instantiating ConfigInstaller at general runtime just seems sensible and a performance improvement. Committed 6e8eb8e and pushed to 8.0.x. Thanks!
Comment #30
cilefen CreditAttribution: cilefen commentedThis caused a regression: #2531878: 'Theme not found' when installing any theme but the theme installs
Comment #31
andypostFiled follow-up to clean-up usage #3017231: Properly deprecate ThemeHandlerInterface install() and uninstall() also replace usage
Comment #32
andypostFiled follow-up for todo #3350933: Fix @todo in \Drupal\Core\Extension\ThemeInstaller::resetSystem()