You are here

function _user_features_get_permissions in Features 7.2

Same name and namespace in other branches
  1. 6 includes/features.user.inc \_user_features_get_permissions()
  2. 7 includes/features.user.inc \_user_features_get_permissions()

Represent the current state of permissions as a perm to role name array map.

@todo The $by_role parameter name is misleading. See #3077296.

Parameters

bool $by_role: Parameter to control the return value. See below.

Return value

string[][]|bool[][] Format:

  • If $by_role is TRUE: $[$permission_name][] = $role_name
  • Otherwise: $[$role_name][$permission_name] = $status
2 calls to _user_features_get_permissions()
user_permission_features_export_render in includes/features.user.inc
Implements hook_features_export_render().
user_permission_features_rebuild in includes/features.user.inc
Implements hook_features_rebuild(). Iterate through default permissions and update the permissions map.

File

includes/features.user.inc, line 297
Features integration for 'user' module.

Code

function _user_features_get_permissions($by_role = TRUE) {
  $map = user_permission_get_modules();
  $roles = _user_features_get_roles();
  $permissions = array();
  foreach (user_role_permissions($roles) as $rid => $role_permissions) {
    if ($by_role) {
      foreach (array_keys(array_filter($role_permissions)) as $permission) {
        if (isset($map[$permission])) {
          $permissions[$permission][] = $roles[$rid];
        }
      }
    }
    else {
      $permissions[$roles[$rid]] = array();
      foreach ($role_permissions as $permission => $status) {
        if (isset($map[$permission])) {
          $permissions[$roles[$rid]][$permission] = $status;
        }
      }
    }
  }
  return $permissions;
}