Problem/Motivation
Discovered while working on #2879087: Use comment access handler instead of hardcoding permissions
Since #3335768: Manually clear cache keys from plugin managers with finite variations instead of using cache tags, \Drupal\Core\Theme\Registry::reset() no longer relies on the theme_registry cache tag. Instead it deletes an explicit list of cache IDs built from the installed themes:
$cids = ['theme_registry:build:modules'];
foreach ($this->themeHandler->listInfo() as $theme_name => $info) {
$cids[] = 'theme_registry:' . $theme_name;
$cids[] = 'theme_registry:runtime:' . $theme_name;
}
$this->cache->deleteMultiple($cids);
However, when no theme is installed, (e.g, in Kernel tests), ThemeInitialization falls back to a pseudo-theme named core. The registry is then built and persisted as theme_registry:core / theme_registry:runtime:core. Since core is never returned by ThemeHandler::listInfo(), these entries are not included in $cids and survive reset().
As a workaround, you should explicitly run:
$this->container->get('cache.default')->delete('theme_registry:core');
Steps to reproduce
See the test from the MR.
Proposed resolution
Make Registry::reset() always include the fallback theme's cache IDs, e.g.:
$cids = ['theme_registry:build:modules'];
$theme_names = ['core', ...array_keys($this->themeHandler->listInfo())];
foreach ($theme_names as $theme_name) {
$cids[] = 'theme_registry:' . $theme_name;
$cids[] = 'theme_registry:runtime:' . $theme_name;
}
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork drupal-3628524
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaComment #4
claudiu.cristeaFix title
Comment #6
claudiu.cristeaComment #7
claudiu.cristeaDisclaimer: LLM helped me to pin the issue when this regressed
Comment #8
claudiu.cristeaComment #9
nisha_j commentedReviewed MR !17341 at commit 1c13c81b.
- Registry::reset() now adds 'core' to the list of theme names. The theme_registry:core and theme_registry:runtime:core caches are now deleted with the other theme registry caches.
- Test-only run (fix reverted, test kept): RegistryTest::testResetFallbackCoreTheme fails.
- With the fix: RegistryTest passes (11 tests, 30 assertions).
- phpcs reports no issues on the changed files.
- Pipeline #989605 passes.
The 'core' theme name is also hard-coded in ThemeInitialization.php, line 113, where the fallback theme is set.
Generated with the help of an LLM.