You are here

function _commons_groups_update_group_permissions in Drupal Commons 7.3

Update the group permission field.

Parameters

$role: The OG role object of which the permissions are being changed.

$permissions: The anonymous user permissions of the group.

File

modules/commons/commons_groups/commons_groups.module, line 172

Code

function _commons_groups_update_group_permissions($role, $permissions) {
  $updated_roles =& drupal_static(__FUNCTION__);
  if (!empty($updated_roles[$role->rid])) {

    // Avoid updating a group subscription twice on the same request.
    return;
  }
  if (!empty($permissions['subscribe without approval'])) {
    $subscribe_type = 'anyone';
  }
  elseif (!empty($permissions['subscribe'])) {
    $subscribe_type = 'approval';
  }
  else {
    $subscribe_type = 'invitation';
  }
  $wrapper = entity_metadata_wrapper($role->group_type, $role->gid);
  if ($wrapper->field_og_subscribe_settings
    ->value() != $subscribe_type) {

    // Mark that the group's permissions were already handled on this request,
    // to avoid saving the group entity more than once.
    $updated_roles[$role->rid] = TRUE;
    $wrapper->field_og_subscribe_settings
      ->set($subscribe_type);
    $wrapper
      ->save();
  }
}