You are here

protected function PermissionHandler::sortPermissions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/PermissionHandler.php \Drupal\user\PermissionHandler::sortPermissions()

Sorts the given permissions by provider name and title.

Parameters

array $all_permissions: The permissions to be sorted.

Return value

array[] Each return permission is an array with the following keys:

  • title: The title of the permission.
  • description: The description of the permission, defaults to NULL.
  • provider: The provider of the permission.
1 call to PermissionHandler::sortPermissions()
PermissionHandler::getPermissions in core/modules/user/src/PermissionHandler.php
Gets all available permissions.

File

core/modules/user/src/PermissionHandler.php, line 206
Contains \Drupal\user\PermissionHandler.

Class

PermissionHandler
Provides the available permissions based on yml files.

Namespace

Drupal\user

Code

protected function sortPermissions(array $all_permissions = array()) {

  // Get a list of all the modules providing permissions and sort by
  // display name.
  $modules = $this
    ->getModuleNames();
  uasort($all_permissions, function (array $permission_a, array $permission_b) use ($modules) {
    if ($modules[$permission_a['provider']] == $modules[$permission_b['provider']]) {
      return $permission_a['title'] > $permission_b['title'];
    }
    else {
      return $modules[$permission_a['provider']] > $modules[$permission_b['provider']];
    }
  });
  return $all_permissions;
}