DrupalDork.com was shut down on September 18, 2013. This is just a snapshot of the site as it appeared then.

D6: Garland Theme for Batch Processing

There's a long-running bug in the Drupal issue queue about a bug that I had to work around this week: when using the Batch API, your site theme will only be used for the first page. As the page reloads to show the progress of the job, the ugly, default Garland theme is used (well, that's not entirely true: it's actually Minnelli, but looks like Garland).

In most cases, this isn't a big deal: during a site install or when running update.php, it doesn't really matter what theme the admins see. In one client's case, though, we're using the Batch API to show progress of a multi-part donation that may take some time to process. In that case, you don't want regular site visitors seeing Minnelli: it's a jarring transition away from the site theme, and to anyone who isn't a seasoned Drupal user, it probably looks like something broke.

It took me a bit to find the solution to this problem. The issue I mentioned above is now being fixed for Drupal 8, but the menu system has changed enough that the patches posted there don't work with the older version of Drupal that I'm working with. After some digging, I found the solution: you need to override your maintenance theme.

  1. Override the maintenance_theme variable in settings.php. Any variable that's retrieved using variable_get() can be completely overridden by setting it in the $confarray. In this case, you just need to add one line to settings.php:

    $conf['maintenance_theme'] = 'my_site_theme';

    Naturally, you'll need to replace my_site_theme with the name of your site theme.

  2. Copy maintenance-page.tpl.php into your theme directory. Go into the modules/system directory at the Drupal root, find maintenance-page.tpl.php, and copy it into your theme directory—the one that matches the name you set for $conf['maintenance_theme'], that is.

Your site theme will now be used for every step in batch processing. It's important to also note that this theme will also be used if you actually do put the site in maintenance mode, since that's what you're overriding. Minnelli will still be used for update.php, though.

I'm not entirely certain that the second step is necessary, since a quick test shows that the batch process still used the site theme even when I removed maintenance-page.tpl.php from the theme directory. It may only be needed for actual maintenance mode, but the comments in settings.php say to copy it, so I copied it.

Category:

Drupal Version:

Comments

i don't know what you are talking about, i used batch api in drupal6 to export data into excel file
and present it as file download and the site doesn't switch theme while processing ..

Hmm, neat trick. I was able to pull this off in D6 by using context to set the theme. It was reeeaaallly driving me nuts because my users can trigger batch jobs often and it looked really bad.

Thanks for the tip.

Thanks!