views_plugin_access_perm.inc
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @file
* Definition of views_plugin_access_perm.
*/
/**
* Access plugin that provides permission-based access control.
*
* @ingroup views_access_plugins
*/
class views_plugin_access_perm extends views_plugin_access {
function access($account) {
return views_check_perm($this->options['perm'], $account);
}
function get_access_callback() {
return array('views_check_perm', array($this->options['perm']));
}
function summary_title() {
$permissions = module_invoke_all('permission');
if (isset($permissions[$this->options['perm']])) {
return $permissions[$this->options['perm']]['title'];
}
return t($this->options['perm']);
}
function option_definition() {
$options = parent::option_definition();
$options['perm'] = array('default' => 'access content');
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$perms = array();
$module_info = system_get_info('module');
// Get list of permissions
foreach (module_implements('permission') as $module) {
$permissions = module_invoke($module, 'permission');
foreach ($permissions as $name => $perm) {
$perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']);
}
}
ksort($perms);
$form['perm'] = array(
'#type' => 'select',
'#options' => $perms,
'#title' => t('Permission'),
'#default_value' => $this->options['perm'],
'#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.'),
);
}
}