views_plugin_access_perm.inc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  13. * {@inheritdoc}
  14. */
  15. public function access($account) {
  16. return views_check_perm($this->options['perm'], $account);
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function get_access_callback() {
  22. return array('views_check_perm', array($this->options['perm']));
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function summary_title() {
  28. $permissions = module_invoke_all('permission');
  29. if (isset($permissions[$this->options['perm']])) {
  30. return $permissions[$this->options['perm']]['title'];
  31. }
  32. return t($this->options['perm']);
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function option_definition() {
  38. $options = parent::option_definition();
  39. $options['perm'] = array('default' => 'access content');
  40. return $options;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function options_form(&$form, &$form_state) {
  46. parent::options_form($form, $form_state);
  47. $perms = array();
  48. $module_info = system_get_info('module');
  49. // Get list of permissions.
  50. foreach (module_implements('permission') as $module) {
  51. $permissions = module_invoke($module, 'permission');
  52. foreach ($permissions as $name => $perm) {
  53. $perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']);
  54. }
  55. }
  56. ksort($perms);
  57. $form['perm'] = array(
  58. '#type' => 'select',
  59. '#options' => $perms,
  60. '#title' => t('Permission'),
  61. '#default_value' => $this->options['perm'],
  62. '#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.'),
  63. );
  64. }
  65. }