Problem/Motivation

There is an issue for batch system that was closed(https://www.drupal.org/project/drupal/issues/539022) but i found an other related issue(https://www.drupal.org/project/drupal/issues/539022#comment-15194405) .

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

Issue fork drupal-3383138

Command icon 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

mibfire created an issue. See original summary.

mibfire’s picture

Patch is attached.

cilefen’s picture

Version: 9.5.x-dev » 11.x-dev
junaidpv’s picture

#2 helped me to solve a problem with a CSV export view using a batch process. Certain paragraph reference field was chosen to render using an overridden twig template. But the output was having column not rendered with that template. Figured out it was because the batch process was using the admin theme instead of the theme that was used to render the original view page.

The patch makes sense.

samit.310@gmail.com made their first commit to this issue’s fork.

samitk’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
prashant.c’s picture

StatusFileSize
new5.02 MB

@mibfire

In my situation, I have the "Gin" theme enabled. When I try to run the batch process, it executes within the Gin theme, which is my active theme, rather than switching to any other theme.

It seems that the batch process is always executed in the default or active theme, not in the admin theme. Am I misunderstanding the issue you're trying to describe?

Batch process active theme

junaidpv’s picture

@Prashant.c Batch process UI is using the active theme but the batch process ajax calls are processed with admin theme.

prashant.c’s picture

@junaidpv

Do you mean executing a batch process in a custom/contrib form using #ajax with an AJAX submit handler?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.