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.
- Override the
maintenance_theme
variable insettings.php
. Any variable that's retrieved usingvariable_get()
can be completely overridden by setting it in the$conf
array. In this case, you just need to add one line tosettings.php
:$conf['maintenance_theme'] = 'my_site_theme';
Naturally, you'll need to replace
my_site_theme
with the name of your site theme. - Copy
maintenance-page.tpl.php
into your theme directory. Go into themodules/system
directory at the Drupal root, findmaintenance-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.
Comments
yakoub abaya (not verified)
Sat 31 Mar 2012, 2:24 am
Permalink
no such problem
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 ..
btopro (not verified)
Mon 2 Apr 2012, 8:53 am
Permalink
Hmm, neat trick. I was able
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.
apanag (not verified)
Fri 10 Aug 2012, 6:46 am
Permalink
Nice!
Thanks for the tip.
Tom (not verified)
Mon 27 Aug 2012, 4:20 pm
Permalink
Nice!
Thanks!