Enabling SDC causes the frontend theme to be used in admin routes

Created on 5 July 2023, over 1 year ago
Updated 28 June 2024, 6 months ago

Problem/Motivation

Enabling SDC causes the frontend theme to be used in admin routes. Drupal\sdc\ComponentNegotiator contains the following line in its constructor:

$this->activeTheme = $this->themeManager->getActiveTheme();

The problem is that the service is created too early in the request, when no route match is available yet. $this->themeManager->getActiveTheme() eventually results in Drupal\user\Theme\AdminNegotiator being triggered with an instance of Drupal\Core\Routing\NullRouteMatch as $route_match argument, which causes the admin negotiator to not be applied and the default negotiator to be used, resulting in the default theme being used in the admin.

Steps to reproduce

Enable the sdc module. I tried it on different projects, with the same outcome. I did not try it on a fresh install, so it might indirectly be caused by a contrib module.

Proposed resolution

Don't call $this->themeManager->getActiveTheme() in the constructor, it's bad practice. @mglaman wrote about it a couple months ago: Dependency injection anti-patterns in Drupal.

🐛 Bug report
Status

Closed: outdated

Version

11.0 🔥

Component
single-directory components 

Last updated about 2 hours ago

Created by

🇧🇪Belgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024