You are here

function og_ui_user_admin_permissions_after_build in Organic groups 7

Helper function to disable the permissions checkboxes.

Every permission can declare to which roles it applies, as some don't make sense if applied to anonymous or authenticated user (e.g. subscribe to group should appear only to anonymous members). A second case for disabling is when using deafult roles and permissions, and the user is browsing a group's permissions page.

1 string reference to 'og_ui_user_admin_permissions_after_build'
og_ui_user_admin_permissions in og_ui/og_ui.admin.inc
Menu callback: administer permissions.

File

og_ui/og_ui.admin.inc, line 591
Admin settings for Organic groups module.

Code

function og_ui_user_admin_permissions_after_build($element) {
  $gid = !empty($element['group']['#value']->gid) ? $element['group']['#value']->gid : 0;

  // Indicate if all checkbes should be disabled.
  $disable = $gid && og_is_group_default_access($gid);

  // Authenticated roles.
  $auth_rids = array_flip(og_roles($gid));

  // Remove the anonymous member from the authenticated roles.
  $anon_rid = array_shift($auth_rids);
  foreach (og_get_permissions() as $key => $perm) {
    $perm['roles'] = drupal_map_assoc($perm['roles']);
    if ($disable || (empty($perm['roles']) || empty($perm['roles'][OG_ANONYMOUS_ROLE]))) {
      $element['checkboxes'][$anon_rid][$key]['#attributes']['disabled'] = TRUE;
    }
    if ($disable || (empty($perm['roles']) || empty($perm['roles'][OG_AUTHENTICATED_ROLE]))) {
      foreach ($auth_rids as $auth_rid) {
        $element['checkboxes'][$auth_rid][$key]['#attributes']['disabled'] = TRUE;
      }
    }
  }
  return $element;
}