By tim.plunkett on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
block_list()
// Drupal 7
$blocks = block_list('sidebar_first');
// Drupal 8
$blocks = entity_load_multiple_by_properties('block', array('theme' => $GLOBALS['theme'], 'region' => 'sidebar_first'));
uasort($blocks, 'Drupal\block\Entity\Block::sort');
Note that the direct approach in D8 let's you also specify the theme, block_list() would only use the current theme.
block_get_blocks_by_region()
The function would load all blocks for a given theme, check access, and render them.
Those are now three different steps.
// Drupal 7
$build = block_get_blocks_by_region('sidebar_first');
// Drupal 8
$blocks = entity_load_multiple_by_properties('block', array('theme' => $GLOBALS['theme'], 'region' => 'sidebar_first'));
uasort($blocks, 'Drupal\block\Entity\Block::sort');
$build = array();
foreach ($blocks as $key => $block) {
if ($block->access('view')) {
$build[$key] = entity_view($block, 'block');
}
}
Impacts:
Module developers
Comments
No $GLOBALS['theme']
As per https://www.drupal.org/node/2324935,
\Drupal::theme()->getActiveTheme()->getName()should be used instead of$GLOBALS['theme'].entity_load_multiple_by
entity_load_multiple_by_properties() is deprecated. Instead consider: