diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-01-27 00:22:27 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-01-27 00:22:27 +0000 |
commit | 2e8ca690ff471b1d6604226e8153f401b1827204 (patch) | |
tree | 546f818191f809271154f26464961e3425dbc72c /modules/block | |
parent | ba5609c11a88f8ab8f42520c3f39eafb69dd463e (diff) | |
download | brdo-2e8ca690ff471b1d6604226e8153f401b1827204.tar.gz brdo-2e8ca690ff471b1d6604226e8153f401b1827204.tar.bz2 |
- Patch #351235 by dmitrig01, webchick, frando, moshe weitzman, et al: hook_page_alter. Oh, behave.
Diffstat (limited to 'modules/block')
-rw-r--r-- | modules/block/block.admin.inc | 2 | ||||
-rw-r--r-- | modules/block/block.module | 55 |
2 files changed, 55 insertions, 2 deletions
diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc index ead47fba0..00afc9bd8 100644 --- a/modules/block/block.admin.inc +++ b/modules/block/block.admin.inc @@ -368,8 +368,6 @@ function template_preprocess_block_admin_display_form(&$variables) { $variables['block_regions'] = $block_regions + array(BLOCK_REGION_NONE => t('Disabled')); foreach ($block_regions as $key => $value) { - // Highlight regions on page to provide visual reference. - drupal_set_content($key, '<div class="block-region">' . $value . '</div>'); // Initialize an empty array for the region. $variables['block_listing'][$key] = array(); } diff --git a/modules/block/block.module b/modules/block/block.module index 318617e8b..c08bac949 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -226,6 +226,61 @@ function block_block_view($delta = 0, $edit = array()) { } /** + * Implementation of hook_page_alter(). + * + * Render blocks into their regions. + */ +function block_page_alter($page) { + global $theme; + + // The theme system might not yet be initialized. We need $theme. + init_theme(); + + // Populate all block regions + $regions = system_region_list($theme); + + // Load all region content assigned via blocks. + foreach (array_keys($regions) as $region) { + // Prevent left and right regions from rendering blocks when 'show_blocks' == FALSE. + if ($page['#show_blocks'] || ($region != 'left' && $region != 'right')) { + // Assign blocks to region. + if ($blocks = block_get_blocks_by_region($region)) { + $page[$region]['blocks'] = $blocks; + } + + // Append region description if we are rendering the block admin page. + $item = menu_get_item(); + if ($item['path'] == 'admin/build/block') { + $description = '<div class="block-region">' . $regions[$region] . '</div>'; + $page[$region]['blocks']['block_description'] = array('#markup' => $description); + } + } + } +} + +/** + * Get a renderable array of a region containing all enabled blocks. + * + * @param $region + * The requested region. + */ +function block_get_blocks_by_region($region) { + $weight = 0; + $build = array(); + if ($list = block_list($region)) { + foreach ($list as $key => $block) { + $build[$key] = array( + '#theme' => 'block', + '#block' => $block, + '#weight' => ++$weight, + ); + } + $build['#sorted'] = TRUE; + } + return $build; +} + +/** * Update the 'block' DB table with the blocks currently exported by modules. * * @return |