You are here

function content_access_disable_checkboxes in Content Access 6

Same name and namespace in other branches
  1. 7 content_access.module \content_access_disable_checkboxes()

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

1 string reference 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.

File

./content_access.admin.inc, line 320
Content access administration UI.

Code

function content_access_disable_checkboxes($element) {
  $access_roles = content_access_get_permission_access('access content');
  $admin_roles = content_access_get_permission_access('administer nodes');
  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>";
    }
    else {
      if (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 administer node 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('administer nodes'),
          )),
        )) . '>';
        $element[$key]['#suffix'] = "</span>";
      }
    }
  }
  return $element;
}