You are here

function content_access_disable_checkboxes in Content Access 7

Same name and namespace in other branches
  1. 6 content_access.admin.inc \content_access_disable_checkboxes()

Formapi #process callback, that disables checkboxes for roles without access to content

2 string references to 'content_access_disable_checkboxes'
content_access_role_based_form in ./content_access.admin.inc
Builds the role based permission form for the given defaults.
content_access_rules_checkboxes_form in content_access_rules/content_access_rules.rules.inc
Returns the form elements for configuring content access per-role permissions.

File

./content_access.module, line 617
Content access module file.

Code

function content_access_disable_checkboxes($element) {
  $access_roles = content_access_get_permission_access('access content');
  $admin_roles = content_access_get_permission_access('bypass node access');
  foreach (element_children($element) as $key) {
    if (!in_array($key, $access_roles) && $key == DRUPAL_ANONYMOUS_RID && !in_array(DRUPAL_AUTHENTICATED_RID, $access_roles)) {
      $element[$key]['#disabled'] = TRUE;
      $element[$key]['#default_value'] = FALSE;
      $element[$key]['#prefix'] = '<span' . drupal_attributes(array(
        'title' => t("This role is lacking the permission '@perm', so it has no access.", array(
          '@perm' => t('access content'),
        )),
      )) . '>';
      $element[$key]['#suffix'] = "</span>";
    }
    elseif (in_array($key, $admin_roles) || $key != DRUPAL_ANONYMOUS_RID && in_array(DRUPAL_AUTHENTICATED_RID, $admin_roles)) {

      // Fix the checkbox to be enabled for users with bypass node access privileges
      $element[$key]['#disabled'] = TRUE;
      $element[$key]['#default_value'] = TRUE;
      $element[$key]['#prefix'] = '<span' . drupal_attributes(array(
        'title' => t("This role has '@perm' permission, so access is granted.", array(
          '@perm' => t('bypass node access'),
        )),
      )) . '>';
      $element[$key]['#suffix'] = "</span>";
    }
  }
  return $element;
}