I've written a function to configure the display of blocks within themes that I think could be added to crud.inc:

/**
 * Enable or disable display of a block in the current theme.
 *
 * An empty value for $region disables the block.
 */
function install_block_enable($theme, $module, $delta, $region='', $weight = 0) {
  $block_regions = system_region_list($theme);
  $status = ($region && array_key_exists($region, $block_regions));
  $throttle = 0;
  db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme);
  db_query("INSERT INTO {blocks} (`status`, `weight`, `region`, `throttle`, `module`, `delta`, `theme`) VALUES (%d, %d, '%s', %d, '%s', '%s', '%s')", $status, $weight, $region, $throttle, $module, $delta, $theme);
}

I've already tried the function in an install profile that I wrote for myself. In order to get it to work properly, I think I had to precede it with a system_theme_data() call, like so:

  $theme_name = 'garland';
  system_theme_data();
  variable_set('theme_default', $theme_name);
  install_block_enable($theme_name, 'user', 1, 'right', -10);
  install_block_enable($theme_name, 'user', 0, 'right', -8);
  install_block_enable($theme_name, 'blog', 0, 'left', -6);
  install_block_enable($theme_name, 'poll', 0, 'left', 0);

Comments

Susurrus’s picture

Status: Active » Needs review

First, it would be better if you could attach this change as a patch file. There're instructions on how to do this in this handbooks.

Regarding the code itself, it may be best to divide this function up a little better into 2 or even 3 functions.

Currently this function does 3 things: enables a block, disables a block, or moves a block to a new location. I propose moving into 3 functions: one would enable, one would disable, and the other would move the block and they'd be named install_block_enable, install_block_disable, and install_block_move. This makes the most sense and keeps this API self-documenting.

dww’s picture

Component: crud.inc » CRUD functions and includes
Status: Needs review » Fixed

Isn't that what install_add_block() and/or install_set_block() already do for you?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.