| 1 |
<?php
|
| 2 |
// $Id: views_plugin_access_perm.inc,v 1.2 2008/09/17 22:26:55 merlinofchaos Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Access plugin that provides permission-based access control.
|
| 6 |
*/
|
| 7 |
class views_plugin_access_perm extends views_plugin_access {
|
| 8 |
function access($account) {
|
| 9 |
return user_access($this->options['perm'], $account);
|
| 10 |
}
|
| 11 |
|
| 12 |
function get_access_callback() {
|
| 13 |
return array('user_access', array($this->options['perm']));
|
| 14 |
}
|
| 15 |
|
| 16 |
function summary_title() {
|
| 17 |
return t($this->options['perm']);
|
| 18 |
}
|
| 19 |
|
| 20 |
function option_defaults(&$options) {
|
| 21 |
$options['perm'] = 'access content';
|
| 22 |
}
|
| 23 |
|
| 24 |
function options_form(&$form, &$form_state) {
|
| 25 |
$perms = array();
|
| 26 |
// Get list of permissions
|
| 27 |
foreach (module_list(FALSE, FALSE, TRUE) as $module) {
|
| 28 |
if ($permissions = module_invoke($module, 'perm')) {
|
| 29 |
$perms[$module] = drupal_map_assoc($permissions);
|
| 30 |
}
|
| 31 |
}
|
| 32 |
$form['perm'] = array(
|
| 33 |
'#type' => 'select',
|
| 34 |
'#options' => $perms,
|
| 35 |
'#title' => t('Permission'),
|
| 36 |
'#default_value' => $this->options['perm'],
|
| 37 |
'#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.'),
|
| 38 |
);
|
| 39 |
}
|
| 40 |
}
|