Gets an array of blocks suitable for drupal_render().
$list: A list of blocks such as that returned by block_list().
A renderable array.
function _block_get_renderable_region($list = array()) {
$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')) || !\Drupal::request()
->isMethodSafe();
foreach ($list as $key => $block) {
$settings = $block
->get('settings');
if ($not_cacheable || in_array($settings['cache'], array(
DRUPAL_NO_CACHE,
DRUPAL_CACHE_CUSTOM,
))) {
// Non-cached blocks get built immediately.
if ($block
->access()) {
$build[$key] = entity_view($block, 'block');
}
}
else {
$key_components = explode('.', $key);
$id = array_pop($key_components);
$build[$key] = array(
'#block' => $block,
'#weight' => $block
->get('weight'),
'#pre_render' => array(
'_block_get_renderable_block',
),
'#cache' => array(
'keys' => array(
$id,
$settings['module'],
),
'granularity' => $settings['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 (isset($build[$key]) && !in_array($block
->get('plugin'), array(
'system_help_block',
'system_main_block',
))) {
$build[$key]['#contextual_links']['block'] = array(
'admin/structure/block/manage',
array(
$key,
),
);
// If there are any nested contextual links, move them to the top level.
if (isset($build[$key]['content']['#contextual_links'])) {
$build[$key]['#contextual_links'] += $build[$key]['content']['#contextual_links'];
unset($build[$key]['content']['#contextual_links']);
}
}
}
return $build;
}