You are here

function mongodb_block_render_blocks in MongoDB 7

Render the content and subject for a set of blocks.

Parameters

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

Return value

array A render array for the blocks.

1 call to mongodb_block_render_blocks()
mongodb_block_page_build in mongodb_block/mongodb_block.module
Implements hook_page_build().

File

mongodb_block/mongodb_block.module, line 143
Controls the visual building blocks a page is constructed with.

Code

function mongodb_block_render_blocks(array $blocks_result) {
  $return = [];
  foreach ($blocks_result as $block) {

    // Copy module and delta out of the _id.
    if (is_array($block) && isset($block['_id'])) {
      $block += $block['_id'];
    }
    $block = (object) $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 (($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') && ($cid = mongodb_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 = [
          '#markup' => $block->content,
        ];
      }

      // Override default block title if a custom display title is present.
      if (!empty($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 = '';
      }
      $return["{$block->module}_{$block->delta}"] = $block;
    }
  }
  return $return;
}