diff --git includes/common.inc includes/common.inc index 755c7f6..84e1375 100644 --- includes/common.inc +++ includes/common.inc @@ -3267,8 +3267,7 @@ function drupal_alter($type, &$data) { function drupal_get_page($content = NULL) { // Initialize page array with defaults. @see hook_elements() - 'page' element. $page = element_info('page'); - $page['content'] = is_array($content) ? $content : array('main' => array('#markup' => $content)); - + system_set_content_block($content); return $page; } diff --git modules/block/block.admin.inc modules/block/block.admin.inc index 52bdd65..4505fee 100644 --- modules/block/block.admin.inc +++ modules/block/block.admin.inc @@ -36,6 +36,9 @@ function block_admin_display_form(&$form_state, $blocks, $theme = NULL) { $block_regions = system_region_list($theme_key) + array(BLOCK_REGION_NONE => '<' . t('none') . '>'); + // Use form submission data to show values if showing the form again. + $blocks = (!empty($form_state['values']) ? $form_state['values'] : $blocks); + // Weights range from -delta to +delta, so delta should be at least half // of the amount of blocks present. This makes sure all blocks in the same // region get an unique weight. @@ -95,6 +98,19 @@ function block_admin_display_form(&$form_state, $blocks, $theme = NULL) { } /** + * Validate main blocks administration form submissions. + */ +function block_admin_display_form_validate(&$form, &$form_state) { + foreach ($form_state['values'] as $key => $block) { + if (($block['module'] == 'system') && ($block['delta'] == 'main') && ($block['region'] == BLOCK_REGION_NONE)) { + form_set_error($key, t('Disabling the main page content block makes your system unusable. You should always enable it to display in a region.')); + // Suggest to put it back into the content region. + form_set_value($form[$key]['region'], 'content', $form_state); + } + } +} + +/** * Process main blocks administration form submissions. */ function block_admin_display_form_submit($form, &$form_state) { diff --git modules/block/block.install modules/block/block.install index f54d4ce..dab0602 100644 --- modules/block/block.install +++ modules/block/block.install @@ -178,6 +178,14 @@ function block_schema() { */ function block_install() { drupal_install_schema('block'); + + // Block should go first so that other modules can alter its output during hook_page_alter(). + db_update('system') + ->fields(array( + 'weight' => -5, + )) + ->condition('name', 'block') + ->execute(); } /** @@ -188,8 +196,10 @@ function block_uninstall() { } /** - * Refresh the block cache. + * Set system.weight for easy use during hook_page_alter(). */ function block_update_7000() { - return array(); + $ret[] = update_sql("UPDATE {system} SET weight = -5 WHERE name = 'block'"); + + return $ret; } diff --git modules/block/block.module modules/block/block.module index db8dd26..1ba451c 100644 --- modules/block/block.module +++ modules/block/block.module @@ -761,6 +761,11 @@ function template_preprocess_block(&$variables) { $variables['block_zebra'] = ($block_counter[$variables['block']->region] % 2) ? 'odd' : 'even'; $variables['block_id'] = $block_counter[$variables['block']->region]++; + if (is_array($variables['block']->content)) { + // Render the block contents if it is not already rendered. + $variables['block']->content = drupal_render($variables['block']->content); + } + $variables['template_files'][] = 'block-' . $variables['block']->region; $variables['template_files'][] = 'block-' . $variables['block']->module; $variables['template_files'][] = 'block-' . $variables['block']->module . '-' . $variables['block']->delta; diff --git modules/system/system.admin.inc modules/system/system.admin.inc index 7f714b0..0801958 100644 --- modules/system/system.admin.inc +++ modules/system/system.admin.inc @@ -179,7 +179,9 @@ function system_themes_form() { } else { // Ensure this theme is compatible with this version of core. - if (!isset($theme->info['core']) || $theme->info['core'] != DRUPAL_CORE_COMPATIBILITY) { + // Require the 'content' region to make sure the main page + // content has a common place in all themes. + if (!isset($theme->info['core']) || ($theme->info['core'] != DRUPAL_CORE_COMPATIBILITY) || (!isset($theme->info['regions']['content']))) { $incompatible_core[] = $theme->name; } if (version_compare(phpversion(), $theme->info['php']) < 0) { diff --git modules/system/system.install modules/system/system.install index 827a066..4a6dadc 100644 --- modules/system/system.install +++ modules/system/system.install @@ -3255,7 +3255,7 @@ function system_update_7020() { } /** - * Add help block to the help region, migrate custom variables to blocks. + * Add new blocks to new region, migrate custom variables to blocks. */ function system_update_7021() { $ret = array(); @@ -3267,6 +3267,8 @@ function system_update_7021() { $themes_with_blocks[] = $theme->name; // Add new system generated help block. $ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES ('system', 'help', '" . $theme->name . "', 1, 0, 'help', '', 1)"); + // Add new system generated main page content block. + $ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES ('system', 'main', '" . $theme->name . "', 1, 0, 'content', '', -1)"); } // Migrate contact form information and user register help to blocks. diff --git modules/system/system.module modules/system/system.module index 61ce58b..aa24949 100644 --- modules/system/system.module +++ modules/system/system.module @@ -889,6 +889,11 @@ function system_user_timezone(&$edit, &$form) { * Implementation of hook_block_list(). */ function system_block_list() { + $blocks['main'] = array( + 'info' => t('Main page content'), + // Cached elsewhere. + 'cache' => BLOCK_NO_CACHE, + ); $blocks['powered-by'] = array( 'info' => t('Powered by Drupal'), 'weight' => '10', @@ -957,6 +962,10 @@ function system_block_save($delta = '', $edit = NULL) { function system_block_view($delta = '') { $block = array(); switch ($delta) { + case 'main': + $block['subject'] = NULL; + $block['content'] = system_set_content_block(); + return $block; case 'powered-by': $image_path = 'misc/' . variable_get('drupal_badge_color', 'powered-blue') . '-' . variable_get('drupal_badge_size', '80x15') . '.png'; $block['subject'] = NULL; @@ -979,6 +988,23 @@ function system_block_view($delta = '') { } /** + * Memory for the page content so that it can be put into a region as a block. + * + * Given the nature of the Drupal page handling, this will be called once with + * a string or array. We store that and return it later as the block is being + * displayed. + */ +function system_set_content_block($content = NULL) { + $content_block = &drupal_static(__FUNCTION__, NULL); + if (!empty($content)) { + $content_block = (is_array($content) ? $content : array('main' => array('#markup' => $content))); + } + else { + return $content_block; + } +} + +/** * Provide a single block on the administration overview page. * * @param $item diff --git profiles/default/default.profile profiles/default/default.profile index e00b361..61acbd5 100644 --- profiles/default/default.profile +++ profiles/default/default.profile @@ -91,9 +91,19 @@ function default_profile_task_list() { */ function default_profile_tasks(&$task, $url) { - // Enable 5 standard blocks. + // Enable some standard blocks. $values = array( array( + 'module' => 'system', + 'delta' => 'main', + 'theme' => 'garland', + 'status' => 1, + 'weight' => 0, + 'region' => 'content', + 'pages' => '', + 'cache' => -1, + ), + array( 'module' => 'user', 'delta' => 'login', 'theme' => 'garland', diff --git profiles/expert/expert.profile profiles/expert/expert.profile index 3b62564..33d7f51 100644 --- profiles/expert/expert.profile +++ profiles/expert/expert.profile @@ -42,9 +42,20 @@ function expert_profile_task_list() { * Perform any final installation tasks for this profile. */ function expert_profile_tasks(&$task, $url) { - // Enable 4 standard blocks. + + // Enable some standard blocks. $values = array( array( + 'module' => 'system', + 'delta' => 'main', + 'theme' => 'garland', + 'status' => 1, + 'weight' => 0, + 'region' => 'content', + 'pages' => '', + 'cache' => -1, + ), + array( 'module' => 'user', 'delta' => 'login', 'theme' => 'garland',