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
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | batch-process.gif | 5.02 MB | prashant.c |
| #2 | drupal-core-batch-api-current-theme-3383138-2.patch | 685 bytes | mibfire |
Issue fork drupal-3383138
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
mibfire commentedPatch is attached.
Comment #3
cilefen commentedComment #4
junaidpv#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.
Comment #7
samitk commentedComment #8
smustgrave commentedComment #9
prashant.c@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?
Comment #10
junaidpv@Prashant.c Batch process UI is using the active theme but the batch process ajax calls are processed with admin theme.
Comment #11
prashant.c@junaidpv
Do you mean executing a batch process in a custom/contrib form using
#ajaxwith an AJAX submit handler?