function Block::sort
Same name in other branches
- 8.9.x core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block::sort()
- 10 core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block::sort()
- 11.x core/modules/block/src/Entity/Block.php \Drupal\block\Entity\Block::sort()
Sorts active blocks by weight; sorts inactive blocks by name.
Overrides ConfigEntityBase::sort
File
-
core/
modules/ block/ src/ Entity/ Block.php, line 216
Class
- Block
- Defines a Block configuration entity class.
Namespace
Drupal\block\EntityCode
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
// Separate enabled from disabled.
$status = (int) $b->status() - (int) $a->status();
if ($status !== 0) {
return $status;
}
// Sort by weight.
$weight = $a->getWeight() - $b->getWeight();
if ($weight) {
return $weight;
}
// Sort by label.
return strcmp($a->label(), $b->label());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.