_block_render_blocks

Versions
7
_block_render_blocks($region_blocks)

Render the content and subject for a set of blocks.

Parameters

$region_blocks An array of block objects such as returned for one region by _block_load_blocks().

Return value

An array of visible blocks as expected by drupal_render().

▾ 2 functions call _block_render_blocks()

block_list in modules/block/block.module
Return all blocks in the specified region for the current user.
dashboard_show_block_content in modules/dashboard/dashboard.module
AJAX callback to display the rendered contents of a specific block.

Code

modules/block/block.module, line 773

<?php
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);

        // Allow modules to modify the block before it is viewed, via either
        // hook_block_view_MODULE_DELTA_alter() or hook_block_view_alter().
        drupal_alter("block_view_{$block->module}_{$block->delta}", $array, $block);
        drupal_alter('block_view', $array, $block);

        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 == '<none>' ? '' : check_plain($block->title);
        }
        if (!isset($block->subject)) {
          $block->subject = '';
        }
        $region_blocks["{$block->module}_{$block->delta}"] = $block;
      }
    }
  }
  return $region_blocks;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.