You are here

function sharedblocks_get_block in Shared Blocks 7.2

Fetch a block in the same manner as _block_render_blocks().

@todo Investigate if this should maybe use ctools_block_content_type_render()?

1 call to sharedblocks_get_block()
sharedblocks_publish_block in ./sharedblocks.publish.inc
Page callback for block publish callback.

File

./sharedblocks.publish.inc, line 82
Publish block page callbacks for the sharedblocks module.

Code

function sharedblocks_get_block($module, $delta) {
  $block = new stdClass();
  $block->module = $module;
  $block->delta = $delta;

  // Reset globals like current path and user during block rendering.
  _sharedblocks_set_globals();
  $array = module_invoke($block->module, 'block_view', $block->delta);

  // Valid PHP function names cannot contain hyphens.
  $delta = str_replace('-', '_', $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}_{$delta}",
  ), $array, $block);
  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,
      );
    }

    // Provide an empty subject if the block hook did not return one.
    if (!isset($block->subject)) {
      $block->subject = '';
    }

    // Customize the output of the block (i.e. running a text filter).
    $block->content['#post_render'][] = 'sharedblocks_post_render_block';

    // Render the content into the final HTML.
    // @todo Figure out how to support #attached information.
    $block->rendered = render($block->content);
  }

  // Only reset globals back once the block is done possibly rendering.
  _sharedblocks_revert_globals();
  return !empty($block->rendered) ? $block : FALSE;
}