You are here

function context_reaction_block::block_list in Context 7.3

Same name and namespace in other branches
  1. 6.3 plugins/context_reaction_block.inc \context_reaction_block::block_list()
  2. 6 plugins/context_reaction_block.inc \context_reaction_block::block_list()

An alternative version of block_list() that provides any context enabled blocks.

1 call to context_reaction_block::block_list()
context_reaction_block::block_get_blocks_by_region in plugins/context_reaction_block.inc
Get a renderable array of a region containing all enabled blocks.

File

plugins/context_reaction_block.inc, line 364

Class

context_reaction_block
Expose blocks as context reactions.

Code

function block_list($region) {
  module_load_include('module', 'block', 'block');
  $context_blocks =& drupal_static('context_reaction_block_list');
  $contexts = context_active_contexts();
  if (!isset($context_blocks)) {
    $info = $this
      ->get_blocks();
    $context_blocks = array();
    foreach ($contexts as $context) {
      $options = $this
        ->fetch_from_context($context);
      if (!empty($options['blocks'])) {
        foreach ($options['blocks'] as $context_block) {
          $bid = "{$context_block['module']}-{$context_block['delta']}";
          if (isset($info[$bid])) {
            $block = (object) array_merge((array) $info[$bid], $context_block);
            $block->context = $context->name;
            $block->title = isset($info[$block->bid]->title) ? $info[$block->bid]->title : NULL;
            $block->cache = isset($info[$block->bid]->cache) ? $info[$block->bid]->cache : DRUPAL_NO_CACHE;
            $context_blocks[$block->region][$block->bid] = $block;
          }
        }
      }
    }
    $this
      ->is_editable_check($context_blocks);
    global $theme;
    $active_regions = $this
      ->system_region_list($theme);

    // Make context renders regions in the same order as core.
    $_context_blocks = array();
    foreach ($active_regions as $r => $name) {
      if (isset($context_blocks[$r])) {
        $_context_blocks[$r] = $context_blocks[$r];
      }
    }
    $context_blocks = $_context_blocks;
    unset($_context_blocks);
    foreach ($context_blocks as $r => $blocks) {

      // Only render blocks in an active region.
      if (array_key_exists($r, $active_regions)) {
        $context_blocks[$r] = _block_render_blocks($blocks);
        $editable = $this
          ->is_editable_region($r);
        foreach ($context_blocks[$r] as $key => $block) {

          // Add the region property to each block.
          $context_blocks[$r][$key]->region = $r;

          // Make blocks editable if allowed.
          if ($editable) {
            $context_blocks[$r][$key] = $this
              ->editable_block($block);
          }
        }
      }

      // Sort blocks.
      uasort($context_blocks[$r], array(
        'context_reaction_block',
        'block_sort',
      ));
    }
  }
  return isset($context_blocks[$region]) ? $context_blocks[$region] : array();
}