W3cubDocs

/Drupal 8

public static function ConfigEntityBase::sort

public static ConfigEntityBase::sort(ConfigEntityInterface $a, ConfigEntityInterface $b)

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

File

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

Class

ConfigEntityBase
Defines a base configuration entity class.

Namespace

Drupal\Core\Config\Entity

Code

public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
  $a_weight = isset($a->weight) ? $a->weight : 0;
  $b_weight = isset($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) ? -1 : 1;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!Entity!ConfigEntityBase.php/function/ConfigEntityBase::sort/8.1.x