function UserPermissionsForm::permissionsByProvider

Same name in other branches
  1. 10 core/modules/user/src/Form/UserPermissionsForm.php \Drupal\user\Form\UserPermissionsForm::permissionsByProvider()
  2. 11.x core/modules/user/src/Form/UserPermissionsForm.php \Drupal\user\Form\UserPermissionsForm::permissionsByProvider()

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.

2 calls to UserPermissionsForm::permissionsByProvider()
UserPermissionsForm::buildForm in core/modules/user/src/Form/UserPermissionsForm.php
Form constructor.
UserPermissionsModuleSpecificForm::permissionsByProvider in core/modules/user/src/Form/UserPermissionsModuleSpecificForm.php
Group permissions by the modules that provide them.
2 methods override UserPermissionsForm::permissionsByProvider()
EntityPermissionsForm::permissionsByProvider in core/modules/user/src/Form/EntityPermissionsForm.php
Group permissions by the modules that provide them.
UserPermissionsModuleSpecificForm::permissionsByProvider in core/modules/user/src/Form/UserPermissionsModuleSpecificForm.php
Group permissions by the modules that provide them.

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

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