You are here

function og_role_change_permissions in Organic groups 7.2

Same name and namespace in other branches
  1. 7 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()

13 calls to og_role_change_permissions()
OgAccess::testOgAccessEntity in ./og.test
Verify og_user_access_entity() returns correct value.
OgFieldAccessTestCase::testOgFieldAccess in og_field_access/og_field_access.test
Group with access field.
OgMigrateRoles::preImport in includes/migrate/7200/og_roles.migrate.inc
Copy all existing global roles to bundle-specific versions. Although similar processing is available through the og_roles_override() function, special handling is necessary to ensure that custom global roles are copied as well as default global roles.
OgNodeAccess::testNodeUpdateAudienceField in ./og.test
Assert a user cannot assign an existing node to a group they don't have "create" permissions.
OgNodeAccess::testNoStrictAccessNodeCreate in ./og.test
Test non-strict access permissions for creating group node.

... See full list

File

./og.module, line 3164
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));
  }
  if (!empty($grant) || !empty($revoke)) {

    // Allow modules to be notified on permission changes.
    $role = og_role_load($rid);
    module_invoke_all('og_role_change_permissions', $role, $grant, $revoke);
  }
}