diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-06-12 09:02:55 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-06-12 09:02:55 +0000 |
commit | d0936908cbf2f8b6c873e9b4d5a2abe279eb8ab7 (patch) | |
tree | b20b1d149e8fa321fbc32503360e5740d3c0ba4f | |
parent | beef6cc65742a34b0c2955f0866a0d9faa96f75e (diff) | |
download | brdo-d0936908cbf2f8b6c873e9b4d5a2abe279eb8ab7.tar.gz brdo-d0936908cbf2f8b6c873e9b4d5a2abe279eb8ab7.tar.bz2 |
- Patch #478744 by moshe weitzman, Frando: simplify block rendering.
-rw-r--r-- | modules/block/block.module | 25 | ||||
-rw-r--r-- | modules/block/block.tpl.php | 4 | ||||
-rw-r--r-- | themes/garland/block.tpl.php | 2 |
3 files changed, 18 insertions, 13 deletions
diff --git a/modules/block/block.module b/modules/block/block.module index 800737298..048c5dba7 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -93,7 +93,7 @@ function block_help($path, $arg) { function block_theme() { return array( 'block' => array( - 'arguments' => array('block' => NULL), + 'arguments' => array('elements' => NULL), 'template' => 'block', ), 'block_admin_display_form' => array( @@ -244,14 +244,17 @@ function block_page_alter($page) { if (!empty($page['#show_blocks']) || ($region != 'left' && $region != 'right')) { // Assign blocks to region. if ($blocks = block_get_blocks_by_region($region)) { - $page[$region]['blocks'] = $blocks; + $page[$region] = $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); + $page[$region]['block_description'] = array( + '#markup' => $description, + '#weight' => 15, + ); } } } @@ -268,8 +271,10 @@ function block_get_blocks_by_region($region) { $build = array(); if ($list = block_list($region)) { foreach ($list as $key => $block) { - $build[$key] = array( - '#theme' => 'block', + $build[$key] = $block->content; + unset($block->content); + $build[$key] += array( + '#theme_wrapper' => 'block', '#block' => $block, '#weight' => ++$weight, ); @@ -727,6 +732,8 @@ function _block_render_blocks($region_blocks) { } } if (isset($block->content) && $block->content) { + // Normalize to the drupal_render() structure. + $block->content = array('content' => is_string($block->content) ? array('#markup' => $block->content) : $block->content); // Override default block title if a custom display title is present. if ($block->title) { // Check plain here to allow module generated titles to keep any @@ -821,7 +828,7 @@ function block_flush_caches() { */ function template_preprocess_block(&$variables) { $block_counter = &drupal_static(__FUNCTION__, array()); - $variables['block'] = $variables['block']['#block']; + $variables['block'] = $variables['elements']['#block']; // All blocks get an independent counter for each region. if (!isset($block_counter[$variables['block']->region])) { $block_counter[$variables['block']->region] = 1; @@ -830,10 +837,8 @@ 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); - } + // Create the $content variable that templates expect. + $variables['content'] = $variables['elements']['#children']; $variables['classes_array'][] = 'block-' . $variables['block']->module; diff --git a/modules/block/block.tpl.php b/modules/block/block.tpl.php index c89d04ef3..77b1fa938 100644 --- a/modules/block/block.tpl.php +++ b/modules/block/block.tpl.php @@ -7,7 +7,7 @@ * * Available variables: * - $block->subject: Block title. - * - $block->content: Block content. + * - $content: Block content. * - $block->module: Module that generated the block. * - $block->delta: An ID for the block, unique within each module. * - $block->region: The block region embedding the current block. @@ -41,6 +41,6 @@ <?php endif;?> <div class="content"> - <?php print $block->content ?> + <?php print $content ?> </div> </div> diff --git a/themes/garland/block.tpl.php b/themes/garland/block.tpl.php index 730b2d4b2..faaa3ef5a 100644 --- a/themes/garland/block.tpl.php +++ b/themes/garland/block.tpl.php @@ -7,5 +7,5 @@ <h2><?php print $block->subject ?></h2> <?php endif;?> - <div class="content"><?php print $block->content ?></div> + <div class="content"><?php print $content ?></div> </div> |