function _block_get_renderable_region

Gets an array of blocks suitable for drupal_render().

Parameters

$list: A list of blocks such as that returned by block_list().

Return value

A renderable array.

1 call to _block_get_renderable_region()
block_get_blocks_by_region in drupal/core/modules/block/block.module
Gets a renderable array of a region containing all enabled blocks.

File

drupal/core/modules/block/block.module, line 345
Controls the visual building blocks a page is constructed with.

Code

function _block_get_renderable_region($list = array()) {
  $weight = 0;
  $build = array();

  // 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'). User 1 being out of
  // the regular 'roles define permissions' schema, it brings too many
  // chances of having unwanted output get in the cache and later be served
  // to other users. We therefore exclude user 1 from block caching.
  $not_cacheable = $GLOBALS['user']->uid == 1 || count(module_implements('node_grants')) || !in_array($_SERVER['REQUEST_METHOD'], array(
    'GET',
    'HEAD',
  ));
  foreach ($list as $key => $block) {
    $build[$key] = array(
      '#block' => $block,
      '#weight' => ++$weight,
      '#theme_wrappers' => array(
        'block',
      ),
    );
    if ($not_cacheable || in_array($block->cache, array(
      DRUPAL_NO_CACHE,
      DRUPAL_CACHE_CUSTOM,
    ))) {

      // Non-cached blocks get built immediately. Provides more content
      // that can be easily manipulated during hook_page_alter().
      $build[$key] = _block_get_renderable_block($build[$key]);
    }
    else {
      $build[$key] += array(
        '#pre_render' => array(
          '_block_get_renderable_block',
        ),
        '#cache' => array(
          'keys' => array(
            $block->module,
            $block->delta,
          ),
          'granularity' => $block->cache,
          'bin' => 'block',
          'tags' => array(
            'content' => TRUE,
          ),
        ),
      );
    }

    // Add contextual links for this block; skip the main content block, since
    // contextual links are basically output as tabs/local tasks already. Also
    // skip the help block, since we assume that most users do not need or want
    // to perform contextual actions on the help block, and the links needlessly
    // draw attention on it.
    if ($key != 'system_main' && $key != 'system_help') {
      $build[$key]['#contextual_links']['block'] = array(
        'admin/structure/block/manage',
        array(
          $block->module,
          $block->delta,
        ),
      );
    }
  }
  $build['#sorted'] = TRUE;
  return $build;
}