Index: modules/block/block.module =================================================================== RCS file: /Users/wright/drupal/local_repo/drupal/modules/block/block.module,v retrieving revision 1.431 diff -u -p -r1.431 block.module --- modules/block/block.module 28 Sep 2010 03:30:37 -0000 1.431 +++ modules/block/block.module 2 Oct 2010 23:58:34 -0000 @@ -330,8 +330,11 @@ function _block_get_renderable_array($li $weight = 0; $build = array(); foreach ($list as $key => $block) { - $build[$key] = $block->content; - unset($block->content); + $build[$key] = array( + '#pre_render' => array('_block_pre_render_block'), + '#block' => $block, + '#weight' => ++$weight, + ); // Add contextual links for this block; skip the main content block, since // contextual links are basically output as tabs/local tasks already. Also @@ -341,12 +344,6 @@ function _block_get_renderable_array($li if ($key != 'system_main' && $key != 'system_help') { $build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($block->module, $block->delta)); } - - $build[$key] += array( - '#block' => $block, - '#weight' => ++$weight, - ); - $build[$key]['#theme_wrappers'][] ='block'; } $build['#sorted'] = TRUE; return $build; @@ -644,9 +641,6 @@ function block_list($region) { if (!isset($blocks[$region])) { $blocks[$region] = array(); } - else { - $blocks[$region] = _block_render_blocks($blocks[$region]); - } return $blocks[$region]; } @@ -792,64 +786,63 @@ function block_block_list_alter(&$blocks } /** - * Render the content and subject for a set of blocks. - * - * @param $region_blocks - * An array of block objects such as returned for one region by _block_load_blocks(). + * Pre-render function: render the content and subject for a block. * - * @return - * An array of visible blocks as expected by drupal_render(). + * @param $element + * A renderable array. */ -function _block_render_blocks($region_blocks) { - foreach ($region_blocks as $key => $block) { - // Render the block content if it has not been created already. - if (!isset($block->content)) { - // Erase the block from the static array - we'll put it back if it has - // content. - unset($region_blocks[$key]); - // Try fetching the block from cache. Block caching is not compatible - // with node_access modules. We also preserve the submission of forms in - // blocks, by fetching from cache only if the request method is 'GET' - // (or 'HEAD'). - if (!count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) { - $array = $cache->data; - } - else { - $array = module_invoke($block->module, 'block_view', $block->delta); +function _block_pre_render_block($element) { + $block = $element['#block']; + + // Render the block content if it has not been created already. + if (!isset($block->content)) { + // Try fetching the block from cache. Block caching is not compatible + // with node_access modules. We also preserve the submission of forms in + // blocks, by fetching from cache only if the request method is 'GET' + // (or 'HEAD'). + if (!count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) { + $array = $cache->data; + } + else { + $array = module_invoke($block->module, 'block_view', $block->delta); - // Allow modules to modify the block before it is viewed, via either - // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter(). - drupal_alter(array('block_view', "block_view_{$block->module}_{$block->delta}"), $array, $block); + // Allow modules to modify the block before it is viewed, via either + // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter(). + drupal_alter(array('block_view', "block_view_{$block->module}_{$block->delta}"), $array, $block); - if (isset($cid)) { - cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY); - } + if (isset($cid)) { + cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY); } + } - if (isset($array) && is_array($array)) { - foreach ($array as $k => $v) { - $block->$k = $v; - } - } - if (isset($block->content) && $block->content) { - // Normalize to the drupal_render() structure. - if (is_string($block->content)) { - $block->content = array('#markup' => $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 - // markup. - $block->subject = $block->title == '' ? '' : check_plain($block->title); - } - if (!isset($block->subject)) { - $block->subject = ''; - } - $region_blocks["{$block->module}_{$block->delta}"] = $block; + if (isset($array) && is_array($array)) { + foreach ($array as $k => $v) { + $block->$k = $v; } } } - return $region_blocks; + + if (isset($block->content) && $block->content) { + // Normalize to the drupal_render() structure. + if (is_string($block->content)) { + $block->content = array('#markup' => $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 + // markup. + $block->subject = $block->title == '' ? '' : check_plain($block->title); + } + if (!isset($block->subject)) { + $block->subject = ''; + } + + // Add the content renderable array to the main element. + $element['content'] = $block->content; + unset($block->content); + $element['#theme_wrappers'][] = 'block'; + } + return $element; } /** Index: modules/dashboard/dashboard.module =================================================================== RCS file: /Users/wright/drupal/local_repo/drupal/modules/dashboard/dashboard.module,v retrieving revision 1.38 diff -u -p -r1.38 dashboard.module --- modules/dashboard/dashboard.module 1 Oct 2010 15:24:18 -0000 1.38 +++ modules/dashboard/dashboard.module 2 Oct 2010 23:58:34 -0000 @@ -478,8 +478,7 @@ function dashboard_show_block_content($m ->fetchObject(); $block_object->enabled = $block_object->page_match = TRUE; $blocks[$module . "_" . $delta] = $block_object; - $block_content = _block_render_blocks($blocks); - $build = _block_get_renderable_array($block_content); + $build = _block_get_renderable_array($blocks); $rendered_block = drupal_render($build); print $rendered_block; drupal_exit();