Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / plugins / views_plugin_access_perm.inc @ 5d12d676

1
<?php
2

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

    
8
/**
9
 * Access plugin that provides permission-based access control.
10
 *
11
 * @ingroup views_access_plugins
12
 */
13
class views_plugin_access_perm extends views_plugin_access {
14

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function access($account) {
19
    return views_check_perm($this->options['perm'], $account);
20
  }
21

    
22
  /**
23
   * {@inheritdoc}
24
   */
25
  public function get_access_callback() {
26
    return array('views_check_perm', array($this->options['perm']));
27
  }
28

    
29
  /**
30
   * {@inheritdoc}
31
   */
32
  public function summary_title() {
33
    $permissions = module_invoke_all('permission');
34
    if (isset($permissions[$this->options['perm']])) {
35
      return $permissions[$this->options['perm']]['title'];
36
    }
37

    
38
    return t($this->options['perm']);
39
  }
40

    
41

    
42
  /**
43
   * {@inheritdoc}
44
   */
45
  public function option_definition() {
46
    $options = parent::option_definition();
47
    $options['perm'] = array('default' => 'access content');
48

    
49
    return $options;
50
  }
51

    
52
  /**
53
   * {@inheritdoc}
54
   */
55
  public function options_form(&$form, &$form_state) {
56
    parent::options_form($form, $form_state);
57
    $perms = array();
58
    $module_info = system_get_info('module');
59

    
60
    // Get list of permissions.
61
    foreach (module_implements('permission') as $module) {
62
      $permissions = module_invoke($module, 'permission');
63
      foreach ($permissions as $name => $perm) {
64
        $perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']);
65
      }
66
    }
67

    
68
    ksort($perms);
69

    
70
    $form['perm'] = array(
71
      '#type' => 'select',
72
      '#options' => $perms,
73
      '#title' => t('Permission'),
74
      '#default_value' => $this->options['perm'],
75
      '#description' => t('Only users with the selected permission flag will be able to access this display. Note that users with "access all views" can see any view, regardless of other permissions.'),
76
    );
77
  }
78

    
79
}