You are here

function system_initialize_theme_blocks in Drupal 6

Same name and namespace in other branches
  1. 4 modules/system.module \system_initialize_theme_blocks()
  2. 5 modules/system/system.module \system_initialize_theme_blocks()

Assign an initial, default set of blocks for a theme.

This function is called the first time a new theme is enabled. The new theme gets a copy of the default theme's blocks, with the difference that if a particular region isn't available in the new theme, the block is assigned to the new theme's default region.

Parameters

$theme: The name of a theme.

2 calls to system_initialize_theme_blocks()
system_admin_theme_submit in modules/system/system.module
Process admin theme form submissions.
system_themes_form_submit in modules/system/system.admin.inc
Process system_themes_form form submissions.

File

modules/system/system.module, line 1080
Configuration system that lets administrators modify the workings of the site.

Code

function system_initialize_theme_blocks($theme) {

  // Initialize theme's blocks if none already registered.
  if (!db_result(db_query("SELECT COUNT(*) FROM {blocks} WHERE theme = '%s'", $theme))) {
    $default_theme = variable_get('theme_default', 'garland');
    $regions = system_region_list($theme);
    $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
    while ($block = db_fetch_array($result)) {

      // If the region isn't supported by the theme, assign the block to the theme's default region.
      if (!array_key_exists($block['region'], $regions)) {
        $block['region'] = system_default_region($theme);
      }
      db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, %d)", $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['cache']);
    }
  }
}