function ConfigEntityBase::sort

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php \Drupal\Core\Config\Entity\ConfigEntityBase::sort()
  2. 10 core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php \Drupal\Core\Config\Entity\ConfigEntityBase::sort()
  3. 8.9.x core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php \Drupal\Core\Config\Entity\ConfigEntityBase::sort()

Helper callback for uasort() to sort configuration entities by weight and label.

1 method overrides ConfigEntityBase::sort()
DateFormat::sort in core/lib/Drupal/Core/Datetime/Entity/DateFormat.php
Helper callback for uasort() to sort configuration entities by weight and label.

File

core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php, line 231

Class

ConfigEntityBase
Defines a base configuration entity class.

Namespace

Drupal\Core\Config\Entity

Code

public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
  $a_weight = $a->weight ?? 0;
  $b_weight = $b->weight ?? 0;
  if ($a_weight == $b_weight) {
    $a_label = $a->label() ?? '';
    $b_label = $b->label() ?? '';
    return strnatcasecmp($a_label, $b_label);
  }
  return $a_weight <=> $b_weight;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.