views_plugin_access_perm.inc

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

File

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