views_plugin_access_perm.inc

  1. 3.x plugins/views_plugin_access_perm.inc
  2. 2.x plugins/views_plugin_access_perm.inc

Definition of views_plugin_access_perm.

File

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