You are here

function og_role_change_permissions in Organic groups 7

Same name and namespace in other branches
  1. 7.2 og.module \og_role_change_permissions()

Change permissions for a user role.

This function may be used to grant and revoke multiple permissions at once. For example, when a form exposes checkboxes to configure permissions for a role, the submitted values may be directly passed on in a form submit handler.

Parameters

$rid: The ID of a group user role to alter.

$permissions: An array of permissions, where the key holds the permission name and the value is an integer or boolean that determines whether to grant or revoke the permission:

array(
  'edit group' => 0,
  'administer group' => 1,
);

Existing permissions are not changed, unless specified in $permissions.

See also

og_role_grant_permissions()

og_role_revoke_permissions()

8 calls to og_role_change_permissions()
OgFieldAccessTestCase::testOgFieldAccess in og_field_access/og_field_access.test
Group with access field.
OgGroupApi::testOgAccessEntity in ./og.test
Verify og_user_access_entity() returns correct value.
OgUiSubscribeTestCase::testOgUiAddPeople in og_ui/og_ui.test
Testing adding people via group/[entity_type]/[etid]/admin/people/add-user.
OgUserPermissionsTestCase::testOgUserRoleChangePermissions in ./og.test
Verify proper permission changes by og_role_change_permissions().
og_roles_override in ./og.module
Create new roles, based on the default roles and permissions.

... See full list

File

./og.module, line 2812
Enable users to create and manage groups with roles and permissions.

Code

function og_role_change_permissions($rid, array $permissions = array()) {

  // Grant new permissions for the role.
  $grant = array_filter($permissions);
  if (!empty($grant)) {
    og_role_grant_permissions($rid, array_keys($grant));
  }

  // Revoke permissions for the role.
  $revoke = array_diff_assoc($permissions, $grant);
  if (!empty($revoke)) {
    og_role_revoke_permissions($rid, array_keys($revoke));
  }
}