function authcache_process_role_restrict in Authenticated User Page Caching (Authcache) 7.2
Form API process callback for authcache_role_restrict element.
Related topics
1 string reference to 'authcache_process_role_restrict'
- authcache_element_info in ./
authcache.module - Implements hook_element_info().
File
- ./
authcache.module, line 1136 - Authenticated User Page Caching (and anonymous users, too!)
Code
function authcache_process_role_restrict($element, &$form_state) {
$authcache_roles = authcache_get_roles();
$allowed_roles = $authcache_roles;
if (!empty($element['#members_only'])) {
unset($allowed_roles[DRUPAL_ANONYMOUS_RID]);
}
$defaults = array(
'custom' => FALSE,
'roles' => $allowed_roles,
);
if (empty($element['#default_value'])) {
$element['#default_value'] = $defaults;
}
else {
$element['#default_value'] = $element['#default_value'] + $defaults;
}
if (empty($allowed_roles)) {
$description = t('Currently there are no roles enabled for authcache. Fix this in <a href="!admin_link">authcache settings</a>.', array(
'!admin_link' => url('admin/config/system/authcache'),
));
}
else {
$description = format_plural(count($allowed_roles), 'The following role is currently enabled for authcache: %roles.', 'The following roles are currently enabled for authcache: %roles.', array(
'%roles' => implode(', ', $allowed_roles),
));
}
$custom_id = drupal_html_id($element['#id'] . '-custom');
$element['custom'] = array(
'#type' => 'checkbox',
'#title' => t('Restrict allowed roles'),
'#default_value' => $element['#default_value']['custom'],
'#description' => $description,
'#disabled' => empty($allowed_roles),
'#id' => $custom_id,
);
$element['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Allowed roles'),
'#options' => $allowed_roles,
'#default_value' => array_keys($element['#default_value']['custom'] ? authcache_get_role_restrict_roles($element['#default_value']) : $allowed_roles),
'#description' => t('Restrict to the selected roles.'),
'#states' => array(
'visible' => array(
'#' . $custom_id => array(
'checked' => TRUE,
),
),
),
);
return $element;
}