protected function GroupPermissionHandler::sortPermissions in Group 8
Same name and namespace in other branches
- 2.0.x src/Access/GroupPermissionHandler.php \Drupal\group\Access\GroupPermissionHandler::sortPermissions()
Sorts the given permissions by provider name first and then by title.
Parameters
array $permissions: The permissions to be sorted.
Return value
array[] An array of permissions as described in ::getPermissions().
See also
\Drupal\group\Access\PermissionHandlerInterface::getPermissions()
2 calls to GroupPermissionHandler::sortPermissions()
- GroupPermissionHandler::getPermissions in src/
Access/ GroupPermissionHandler.php - Gets all defined group permissions.
- GroupPermissionHandler::getPermissionsByGroupType in src/
Access/ GroupPermissionHandler.php - Gets all defined group permissions for a group type.
File
- src/
Access/ GroupPermissionHandler.php, line 269
Class
- GroupPermissionHandler
- Provides the available permissions based on yml files.
Namespace
Drupal\group\AccessCode
protected function sortPermissions(array $permissions = []) {
$modules = $this
->getModuleNames();
// Sort all permissions by provider, section and title, in that order.
uasort($permissions, function (array $permission_a, array $permission_b) use ($modules) {
if ($permission_a['provider'] == $permission_b['provider']) {
if ($permission_a['section'] == $permission_b['section']) {
// All permissions should have gone through ::completePermission() so
// the titles are \Drupal\Core\StringTranslation\TranslatableMarkup.
$title_a = $permission_a['title']
->__toString();
$title_b = $permission_b['title']
->__toString();
return strip_tags($title_a) > strip_tags($title_b);
}
else {
return $permission_a['section'] > $permission_b['section'];
}
}
else {
return $modules[$permission_a['provider']] > $modules[$permission_b['provider']];
}
});
return $permissions;
}