public static function WorkflowConfigTransition::sort in Workflow 8
Helper callback for uasort() to sort configuration entities by weight and label.
Overrides ConfigEntityBase::sort
File
- src/
Entity/ WorkflowConfigTransition.php, line 157
Class
- WorkflowConfigTransition
- Workflow configuration entity to persistently store configuration.
Namespace
Drupal\workflow\EntityCode
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
// Sort the entities using the entity class's sort() method.
// See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
/** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $a */
/** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $b */
if (!$a
->getFromSid() || !$b
->getFromSid()) {
return 0;
}
// First sort on From-State.
$from_state_a = $a
->getFromState();
$from_state_b = $b
->getFromState();
if ($from_state_a->weight < $from_state_b->weight) {
return -1;
}
if ($from_state_a->weight > $from_state_b->weight) {
return +1;
}
// Then sort on To-State.
$to_state_a = $a
->getToState();
$to_state_b = $b
->getToState();
if ($to_state_a->weight < $to_state_b->weight) {
return -1;
}
if ($to_state_a->weight > $to_state_b->weight) {
return +1;
}
return 0;
}