function block_theme_initialize

7.x block.module block_theme_initialize($theme)

Assigns 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.


$theme: The name of a theme.

2 calls to block_theme_initialize()
block_themes_enabled in drupal/modules/block/block.module
Initializes blocks for enabled themes.
hook_themes_enabled in drupal/modules/system/theme.api.php
Respond to themes being enabled.


drupal/modules/block/block.module, line 626
Controls the visual building blocks a page is constructed with.


function block_theme_initialize($theme) {
  // Initialize theme's blocks if none already registered.
  $has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $theme))->fetchField();
  if (!$has_blocks) {
    $default_theme = variable_get('theme_default', 'bartik');
    // Apply only to new theme's visible regions.
    $regions = system_region_list($theme, REGIONS_VISIBLE);
    $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC));
    foreach ($result as $block) {
      // If the region isn't supported by the theme, assign the block to the theme's default region.
      if ($block['status'] && !isset($regions[$block['region']])) {
        $block['region'] = system_default_region($theme);
      $block['theme'] = $theme;
      drupal_write_record('block', $block);