You are here

protected function ServerListBuilder::sortByStatusThenAlphabetically in OAuth2 Server 2.0.x

Same name and namespace in other branches
  1. 8 src/ServerListBuilder.php \Drupal\oauth2_server\ServerListBuilder::sortByStatusThenAlphabetically()

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 ServerListBuilder::sortByStatusThenAlphabetically()
ServerListBuilder::render in src/ServerListBuilder.php
Builds the entity listing as renderable array for table.html.twig.

File

src/ServerListBuilder.php, line 131

Class

ServerListBuilder
Builds a listing of oauth2 server entities.

Namespace

Drupal\oauth2_server

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;
    }
  });
}