Directory default variable isn't updated after changing the active theme

Created on 1 August 2023, over 1 year ago
Updated 6 August 2023, over 1 year ago

Problem/Motivation

The yoast_seo module renders an entity in the frontend theme while in an admin theme context, in order to analyse the HTML output. This works most of the time, except if a template in the frontend theme uses the directory default variable.

The documentation of template_preprocess() says this about the output of _template_preprocess_default_variables():

variables that don't depend on hook and don't change during a single page request.

This is a wrong assumption. The default variables contain the directory variable, which depends on the active theme and that can change during a single page request.

Steps to reproduce

  1. Use the directory variable in an include somewhere in your frontend theme.
  2. Install and configure the Yoast SEO module. Change a field on the entity form, which causes an AJAX request to re-render the entity.
  3. The AJAX request will fail, because Twig is looking for a component of your frontend theme in the admin theme.

Proposed resolution

Move setting the directory variable from _template_preprocess_default_variables() to template_preprocess(). This way it isn't included in the $drupal_static_fast variable and it can be reset from ThemeManager::render by unsetting the $variables['directory'] variable if it differs from $active_theme->getPath().

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Theme 

Last updated about 20 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

Production build 0.71.5 2024