Generated with the help of an LLM.
Problem/Motivation
BatchNegotiator::determineActiveTheme() loads the batch only when $request->request->has('id'). That is the POST body. Batch URLs carry the ID in the query string (/batch?id=N&op=start), so the lookup never runs.
Normally _batch_page() loads the batch into batch_get() before the theme is initialized, and the negotiator finds it there. If the theme is initialized while the batch is being unserialized, the negotiator finds nothing. A stored object can do this in __wakeup(). ViewExecutable does.
Steps to reproduce
Store a batch with theme set to test_theme and an object that calls ThemeManager::getActiveTheme() in __wakeup(). Set the default theme to stark. Call BatchStorage::load() for /batch?id=N&op=start. The active theme is stark. Expected: test_theme.
Proposed resolution
Read the ID from $request->query. Skip the lookup while the negotiator is already loading the batch. Otherwise unserializing the batch calls the negotiator again. Cover both with kernel tests.
Remaining tasks
- Review the test-only change (fails without the fix).
- Review the fix.
- Backport to 11.x.
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
None.
Issue fork drupal-3636379
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
volegerComment #4
volegerComment #5
volegerThe first fix commit (4402a87c65c) broke
UserBatchActionTestwith a call stack overflow.BatchStorage::load()unserializes the batch. The batch in that test holds aViewExecutable, andViewExecutable::__wakeup()initializes the theme. That callsBatchNegotiatoragain, which loads the batch again.The earlier code never hit this, because the lookup branch could not run.
Commit 55b71e4a2c3 adds a flag, so the negotiator skips the lookup while it is already loading the batch. It adds a kernel test with an object that initializes the theme in
__wakeup(). The test fails without the flag.A batch with such an object gets the batch theme. The nested negotiation returns NULL, and the outer negotiation sets the batch theme afterwards. With default theme
starkand batch themetest_theme, the active theme afterBatchStorage::load()isstarkon unfixed code andtest_themeon this branch. 91f3c883d93 changes the test to use these two themes.Comment #6
volegerUpdate IS
Comment #7
voleger