function PermissionHandler::sortPermissions

Same name in other branches
  1. 8.9.x core/modules/user/src/PermissionHandler.php \Drupal\user\PermissionHandler::sortPermissions()
  2. 10 core/modules/user/src/PermissionHandler.php \Drupal\user\PermissionHandler::sortPermissions()
  3. 11.x 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[] An array with the same structure as PermissionHandlerInterface::getPermissions().

See also

\Drupal\user\PermissionHandlerInterface::getPermissions()

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 205

Class

PermissionHandler
Provides the available permissions based on yml files.

Namespace

Drupal\user

Code

protected function sortPermissions(array $all_permissions = []) {
    // 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;
}

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