Projet

Général

Profil

Paste
Télécharger (1,84 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / plugins / views_plugin_access_role.inc @ 7547bb19

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_plugin_access_role.
6
 */
7

    
8
/**
9
 * Access plugin that provides role-based access control.
10
 *
11
 * @ingroup views_access_plugins
12
 */
13
class views_plugin_access_role extends views_plugin_access {
14
  function access($account) {
15
    return views_check_roles(array_filter($this->options['role']), $account);
16
  }
17

    
18
  function get_access_callback() {
19
    return array('views_check_roles', array(array_filter($this->options['role'])));
20
  }
21

    
22
  function summary_title() {
23
    $count = count($this->options['role']);
24
    if ($count < 1) {
25
      return t('No role(s) selected');
26
    }
27
    elseif ($count > 1) {
28
      return t('Multiple roles');
29
    }
30
    else {
31
      $rids = views_ui_get_roles();
32
      $rid = reset($this->options['role']);
33
      return check_plain($rids[$rid]);
34
    }
35
  }
36

    
37

    
38
  function option_definition() {
39
    $options = parent::option_definition();
40
    $options['role'] = array('default' => array());
41

    
42
    return $options;
43
  }
44

    
45
  function options_form(&$form, &$form_state) {
46
    parent::options_form($form, $form_state);
47
    $form['role'] = array(
48
      '#type' => 'checkboxes',
49
      '#title' => t('Role'),
50
      '#default_value' => $this->options['role'],
51
      '#options' => array_map('check_plain', views_ui_get_roles()),
52
      '#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.'),
53
    );
54
  }
55

    
56
  function options_validate(&$form, &$form_state) {
57
    if (!array_filter($form_state['values']['access_options']['role'])) {
58
      form_error($form['role'], t('You must select at least one role if type is "by role"'));
59
    }
60
  }
61

    
62
  function options_submit(&$form, &$form_state) {
63
    // I hate checkboxes.
64
    $form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']);
65
  }
66
}