Batch API should use the current theme to run the batches

Created on 24 August 2023, over 1 year ago
Updated 22 July 2024, 5 months ago

Problem/Motivation

There is an issue for batch system that was closed( https://www.drupal.org/project/drupal/issues/539022 ๐Ÿ› Batch API should use the current theme to run the batches Fixed ) but i found an other related issue( https://www.drupal.org/project/drupal/issues/539022#comment-15194405 ๐Ÿ› Batch API should use the current theme to run the batches Fixed ) .

I am quoting this from the old issue:

There is an issue with "applies" method of BatchNegotiator class. This doesn't take the "system.batch_page.json" route into account. So for example while the default theme is used on the "system.batch_page.html" route the admin theme is used on "system.batch_page.json" route. Question is why "system.batch_page.json" route is not taken into account in the "applies" method? In my opinion this should be consistent through the whole batch process regardless of this is the batch page("system.batch_page.html") or the batch ajax calls("system.batch_page.json").

Also the following is how the theme is set for the batch at the beginning.

function batch_process($redirect = NULL, Url $url = NULL, $redirect_callback = NULL) {
  $batch =& batch_get();

  $activeThemeName = \Drupal::service('theme.manager')->getActiveTheme();
  $request = \Drupal::request();

  if (isset($batch)) {
    // Add process information
    $process_info = [
      'current_set' => 0,
      'progressive' => TRUE,
      'url' => $url ?? Url::fromRoute('system.batch_page.html'),
      'source_url' => Url::fromRouteMatch(\Drupal::routeMatch())->mergeOptions(['query' => \Drupal::request()->query->all()]),
      'batch_redirect' => $redirect,
      'theme' => \Drupal::theme()->getActiveTheme()->getName(),
      'redirect_callback' => $redirect_callback,
    ];

=>

'theme' => \Drupal::theme()->getActiveTheme()->getName(),

So this should apply to the ajax calls too.

Steps to reproduce

- Run a batch with normal path, without admin theme.
- Check which theme is used when data is processed through ajax calls in batch.

Proposed resolution

I created a patch for this issue.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Batchย  โ†’

Last updated about 8 hours ago

  • Maintained by
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom @John Cook
Created by

๐Ÿ‡ญ๐Ÿ‡บHungary mibfire

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024