Sorts active blocks by region then weight; sorts inactive blocks by name.
protected function sort(Block $a, Block $b) {
static $regions;
// We need the region list to correctly order by region.
if (!isset($regions)) {
$regions = array_flip(array_keys($this->regions));
$regions[BLOCK_REGION_NONE] = count($regions);
}
// Separate enabled from disabled.
$status = $b
->get('status') - $a
->get('status');
if ($status) {
return $status;
}
// Sort by region (in the order defined by theme .info.yml file).
$aregion = $a
->get('region');
$bregion = $b
->get('region');
if (!empty($aregion) && !empty($bregion) && ($place = $regions[$aregion] - $regions[$bregion])) {
return $place;
}
// Sort by weight, unless disabled.
if ($a
->get('region') != BLOCK_REGION_NONE) {
$weight = $a
->get('weight') - $b
->get('weight');
if ($weight) {
return $weight;
}
}
// Sort by label.
return strcmp($a
->label(), $b
->label());
}