I am attempting to attach a block to another block via hook_block_view_alter. The source block is a menu_block and the block to be attached is a view block, but the type of block shouldn't matter to the solution.
Here is the code used to attach the block. Assume that block_attached_block
is populated with the bid of the block and at the point where I am altering the render array I have a fully rendered block.
function MODULE_block_view_alter(&$data, $block) {
if (!empty($block->block_attached_block)) {
// load the attached block from the database
$attached_block = db_select('block', 'b')
->fields('b')
->condition('b.bid', $block->block_attached_block)
->execute()
->fetchObject();
// render the block
$block_content = _block_render_blocks(array($attached_block));
$build = _block_get_renderable_array($block_content);
$block_rendered = drupal_render($build);
// attach the block
$data['block_attached_block'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('block_attached_block'),
),
'block' => array(
'#markup' => $block_rendered,
),
);
}
}
If I render $data
at this point I see the attached block rendered perfectly.
drupal_render($data);
However, when I load the page the attached block is missing. The documentation is pretty light.
My question is how do I get the rendered block to output on the page.
$data['content']['block_attached_block'] = ...
? A$block
as returned fromhook_block_info
isn't a render array, confusingly, the render array is actually in the innercontent
element