diff options
Diffstat (limited to 'modules/block')
-rw-r--r-- | modules/block/block.module | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/modules/block/block.module b/modules/block/block.module index a44b910a4..727f526b5 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -436,7 +436,7 @@ function block_user_validate(&$edit, &$account, $category = NULL) { } /** - * Implementation of hook_form_FORM_ID_form_alter(). + * Implementation of hook_form_FORM_ID_alter(). */ function block_form_system_performance_settings_alter(&$form, &$form_state) { @@ -475,6 +475,63 @@ function block_form_system_performance_settings_alter(&$form, &$form_state) { } /** + * Implementation of hook_form_FORM_ID_alter(). + */ +function block_form_system_themes_form_alter(&$form, &$form_state) { + $form['#submit'][] = 'block_system_themes_form_submit'; +} + +/** + * Initialize blocks for enabled themes. + */ +function block_system_themes_form_submit(&$form, &$form_state) { + if ($form_state['values']['op'] == t('Save configuration')) { + if (is_array($form_state['values']['status'])) { + foreach ($form_state['values']['status'] as $key => $choice) { + if ($choice || $form_state['values']['theme_default'] == $key) { + block_initialize_theme_blocks($key); + } + } + } + if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != variable_get('admin_theme', 0)) { + // If we're changing themes, make sure the theme has its blocks initialized. + $result = db_result(db_query("SELECT COUNT(*) FROM {block} WHERE theme = '%s'", $form_state['values']['admin_theme'])); + if (!$result) { + block_initialize_theme_blocks($form_state['values']['admin_theme']); + } + } + } +} + +/** + * 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. + * + * @param $theme + * The name of a theme. + */ +function block_initialize_theme_blocks($theme) { + // Initialize theme's blocks if none already registered. + if (!(db_result(db_query("SELECT COUNT(*) FROM {block} WHERE theme = '%s'", $theme)))) { + $default_theme = variable_get('theme_default', 'garland'); + $regions = system_region_list($theme); + $result = db_query("SELECT * FROM {block} 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 {block} (module, delta, theme, status, weight, region, visibility, pages, custom, cache) 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['cache']); + } + } +} + +/** * Return all blocks in the specified region for the current user. * * @param $region |