2
// $Id: views_plugin_access_role.inc,v 1.2 2009/01/07 23:31:13 merlinofchaos Exp $
5
* Access plugin that provides role-based access control.
7
class views_plugin_access_role extends views_plugin_access {
8
function access($account) {
9
$roles = array_keys($account->roles);
10
$roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
11
return array_intersect(array_filter($this->options['role']), $roles);
14
function get_access_callback() {
15
return array('views_check_roles', array(array_filter($this->options['role'])));
18
function summary_title() {
19
$count = count($this->options['role']);
21
return t('No role(s) selected');
23
else if ($count > 1) {
24
return t('Multiple roles');
27
$rids = views_ui_get_roles();
28
$rid = array_shift($this->options['role']);
33
function option_defaults(&$options) {
34
$options['role'] = array();
37
function options_form(&$form, &$form_state) {
38
$form['role'] = array(
39
'#type' => 'checkboxes',
40
'#title' => t('Role'),
41
'#default_value' => $this->options['role'],
42
'#options' => views_ui_get_roles(),
43
'#description' => t('Only the checked roles will be able to access this display. Note that users with "access all views" can see any view, regardless of role.'),
47
function options_validate(&$form, &$form_state) {
48
if (!array_filter($form_state['values']['access_options']['role'])) {
49
form_error($form['role'], t('You must select at least one role if type is "by role"'));
53
function options_submit(&$form, &$form_state) {
55
$form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']);