function BlockPluginCollection::getAllByRegion
Same name in other branches
- 8.x-3.x src/Plugin/BlockPluginCollection.php \Drupal\ctools\Plugin\BlockPluginCollection::getAllByRegion()
Returns all blocks keyed by their region.
Return value
array An associative array keyed by region, containing an associative array of block plugins.
File
-
src/
Plugin/ BlockPluginCollection.php, line 29
Class
- BlockPluginCollection
- Provides a collection of block plugins.
Namespace
Drupal\ctools\PluginCode
public function getAllByRegion() {
$region_assignments = [];
foreach ($this as $block_id => $block) {
$configuration = $block->getConfiguration();
$region = $configuration['region'] ?? NULL;
$region_assignments[$region][$block_id] = $block;
}
foreach ($region_assignments as $region => $region_assignment) {
// @todo Determine the reason this needs error suppression.
@uasort($region_assignment, function (BlockPluginInterface $a, BlockPluginInterface $b) {
$a_config = $a->getConfiguration();
$a_weight = $a_config['weight'] ?? 0;
$b_config = $b->getConfiguration();
$b_weight = $b_config['weight'] ?? 0;
if ($a_weight == $b_weight) {
return strcmp($a->label(), $b->label());
}
return $a_weight > $b_weight ? 1 : -1;
});
$region_assignments[$region] = $region_assignment;
}
return $region_assignments;
}