You are here

function system_initialize_theme_blocks in Drupal 5

Same name and namespace in other branches
  1. 4 modules/system.module \system_initialize_theme_blocks()
  2. 6 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.

3 calls to system_initialize_theme_blocks()
system_admin_theme_submit in modules/system/system.module
system_themes_submit in modules/system/system.module
system_update_145 in modules/system/system.install

File

modules/system/system.module, line 1055
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_num_rows(db_query("SELECT module 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) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)", $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
    }
  }
}