Configuring Drupal blocks when using the Domain Access module

Date: Mon Oct 04 2010 Drupal Tutorial »»»» Drupal Planet
Following on from my blog post the other day, Looking at (and a debugging tip) the Domain module for Drupal, I want to look at one of the gaps in the Domain Access module. Out of the box it does not modify the blocks configuration pages, meaning that out of the box all configured blocks show up for all domains. This is unlikely to be what you want, instead what's likely is to have different blocks for different domains.

Today I moved one of my sites, Social Media for Social Good, onto this site using the domain module. The blocks on the site were configured correctly for and I thought it would be as simple as configuring each block and checking the checkboxes I assumed would be there to select the domains on which the block should be displayed. The Domain Access module has been really good about adding domain selection checkboxes to all sorts of configuration forms, I thought that surely the Blocks configuration pages would have the domain selection checkboxes as well. Unfortunately it did not.

Fortunately someone else has already developed the necessary module, Domain Blocks.

It's as simple as dropping it in sites/all/modules and enabling the module, and now the blocks configuration pages have domain selection checkboxes. Slick.

Unfortunately the result isn't entirely desirable, and it has to do with a core flaw in the blocks system. Yes the domain selection checkboxes are there but as you add domains it becomes more and more complex to determine which block needs to go on what page and on what domain. This generic problem with Drupal has a pair of fixes available with the Context and Panels modules.

The problem is not so bad if your rules for displaying blocks are simple.

For instance the simplest case is to display all blocks on all pages of all domains. In that case simply set up the blocks and you're good to go.

A slightly more complex case is a single domain but you want to control what pages the blocks appear on. Out of the box this is configured with page url patterns.

Where multiple domains creates a lot of complexity is when you want a different set of blocks per domain (and maybe per section of each domain). For example if you want a block to contain feedburner buttons or other chiclets to assist your viewers in subscribing to the site. The URL's to subscribe to each site varies based on the site, obviously. Clearly one block per domain is required for these buttons. It's possible to have several blocks each of which has to be different per domain, and quickly the total number of blocks balloons.

Ensuring each block appears on only the correct domain(s) means editing each block configuration, and checking off the checkboxes. Tedious.

I've only played a bit with the Context module but it turns this issue inside out. One would set up contexts for given conditions, then configure the blocks appropriate for that condition. Unfortunately the Context module doesn't do anything about Domain Access.