function user_role_permissions

Determine the permissions for one or more roles.

Parameters

$roles: An array whose values are the role IDs of interest, such as $user->roles.

Return value

An array indexed by role ID. Each value is an array whose keys are the permission strings for the given role ID.

3 calls to user_role_permissions()
FieldUIUpgradePathTest::testFieldUIPermissions in drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUIUpgradePathTest.php
Tests Field UI permissions upgrade path.
user_access in drupal/core/modules/user/user.module
Determine whether the user has a given privilege.
user_admin_permissions in drupal/core/modules/user/user.admin.inc
Menu callback: administer permissions.
4 string references to 'user_role_permissions'
RoleStorageController::resetCache in drupal/core/modules/user/lib/Drupal/user/RoleStorageController.php
Resets the internal, static entity cache.
UserPermissionsTest::testUserPermissionChanges in drupal/core/modules/user/lib/Drupal/user/Tests/UserPermissionsTest.php
Change user permissions and check user_access().
user_role_grant_permissions in drupal/core/modules/user/user.module
Grant permissions to a user role.
user_role_revoke_permissions in drupal/core/modules/user/user.module
Revoke permissions from a user role.

File

drupal/core/modules/user/user.module, line 419
Enables the user registration and login system.

Code

function user_role_permissions($roles) {
  $cache =& drupal_static(__FUNCTION__, array());
  $role_permissions = $fetch = array();
  foreach ($roles as $rid) {
    if (isset($cache[$rid])) {
      $role_permissions[$rid] = $cache[$rid];
    }
    else {

      // Add this rid to the list of those needing to be fetched.
      $fetch[] = $rid;

      // Prepare in case no permissions are returned.
      $cache[$rid] = array();
    }
  }
  if ($fetch) {

    // Get from the database permissions that were not in the static variable.
    // Only role IDs with at least one permission assigned will return rows.
    $result = db_query("SELECT rid, permission FROM {role_permission} WHERE rid IN (:fetch)", array(
      ':fetch' => $fetch,
    ));
    foreach ($result as $row) {
      $cache[$row->rid][$row->permission] = TRUE;
    }
    foreach ($fetch as $rid) {

      // For every rid, we know we at least assigned an empty array.
      $role_permissions[$rid] = $cache[$rid];
    }
  }
  return $role_permissions;
}