You are here

protected function UserPermissionsForm::permissionsByProvider in Drupal 10

Group permissions by the modules that provide them.

Return value

string[][] A nested array. The outer keys are modules that provide permissions. The inner arrays are permission names keyed by their machine names.

1 call to UserPermissionsForm::permissionsByProvider()
UserPermissionsForm::buildForm in core/modules/user/src/Form/UserPermissionsForm.php
Form constructor.

File

core/modules/user/src/Form/UserPermissionsForm.php, line 91

Class

UserPermissionsForm
Provides the user permissions administration form.

Namespace

Drupal\user\Form

Code

protected function permissionsByProvider() : array {
  $permissions = $this->permissionHandler
    ->getPermissions();
  $permissions_by_provider = [];
  foreach ($permissions as $permission_name => $permission) {
    $permissions_by_provider[$permission['provider']][$permission_name] = $permission;
  }

  // Move the access content permission to the Node module if it is installed.
  // @todo Add an alter so that this section can be moved to the Node module.
  if ($this->moduleHandler
    ->moduleExists('node')) {

    // Insert 'access content' before the 'view own unpublished content' key
    // in order to maintain the UI even though the permission is provided by
    // the system module.
    $keys = array_keys($permissions_by_provider['node']);
    $offset = (int) array_search('view own unpublished content', $keys);
    $permissions_by_provider['node'] = array_merge(array_slice($permissions_by_provider['node'], 0, $offset), [
      'access content' => $permissions_by_provider['system']['access content'],
    ], array_slice($permissions_by_provider['node'], $offset));
    unset($permissions_by_provider['system']['access content']);
  }
  return $permissions_by_provider;
}