You are here

protected function IndexListBuilder::sortByStatusThenAlphabetically in Search API 8

Sorts an array of entities by status and then alphabetically.

Will preserve the key/value association of the array.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface[] $entities: An array of config entities.

1 call to IndexListBuilder::sortByStatusThenAlphabetically()
IndexListBuilder::loadGroups in src/IndexListBuilder.php
Loads search servers and indexes, grouped by servers.

File

src/IndexListBuilder.php, line 321

Class

IndexListBuilder
Builds a listing of search index entities.

Namespace

Drupal\search_api

Code

protected function sortByStatusThenAlphabetically(array &$entities) {
  uasort($entities, function (ConfigEntityInterface $a, ConfigEntityInterface $b) {
    if ($a
      ->status() == $b
      ->status()) {
      return strnatcasecmp($a
        ->label(), $b
        ->label());
    }
    else {
      return $a
        ->status() ? -1 : 1;
    }
  });
}