You are here

class spaces_plugin_access_spaces_feature in Spaces 7.3

Same name and namespace in other branches
  1. 6.3 includes/spaces_plugin_access_spaces_feature.inc \spaces_plugin_access_spaces_feature
  2. 6 includes/spaces_plugin_access_spaces_feature.inc \spaces_plugin_access_spaces_feature
  3. 6.2 includes/spaces_plugin_access_spaces_feature.inc \spaces_plugin_access_spaces_feature
  4. 7 includes/spaces_plugin_access_spaces_feature.inc \spaces_plugin_access_spaces_feature

Provides access control for views by checking against the current space's feature settings. Optionally allows a permission to be checked in addition to the first feature access control check.

This access plugin delegates access control first to spaces_feature_access() which will check whether the user can first access content, then the active space type's 'feature_access' method will be called. If implementing your own space type you have the ability to define your own access control. See 'space_og' class in Spaces OG module for an example implementation.

Hierarchy

Expanded class hierarchy of spaces_plugin_access_spaces_feature

1 string reference to 'spaces_plugin_access_spaces_feature'
spaces_views_plugins in includes/spaces.views.inc
Implements hook_views_plugins().

File

includes/spaces_plugin_access_spaces_feature.inc, line 14

View source
class spaces_plugin_access_spaces_feature extends views_plugin_access {

  /**
   * Check access directly.
   */
  function access($account) {
    $feature = $this->options['spaces_feature'] == 0 ? $this
      ->get_my_feature() : $this->options['spaces_feature'];
    if (!empty($this->options['perm'])) {
      return spaces_access_feature_perms('view', $feature, NULL, NULL, array(
        $this->options['perm'],
      ));
    }
    return spaces_access_feature('view', $feature, NULL);
  }

  /**
   * Provide the access check as a callback.
   */
  function get_access_callback() {
    $feature = empty($this->options['spaces_feature']) ? $this
      ->get_my_feature() : $this->options['spaces_feature'];
    if (!empty($this->options['perm'])) {
      return array(
        'spaces_access_feature_perms',
        array(
          'view',
          $feature,
          NULL,
          NULL,
          array(
            $this->options['perm'],
          ),
        ),
      );
    }
    return array(
      'spaces_access_feature',
      array(
        'view',
        $feature,
        NULL,
      ),
    );
  }

  /**
   * Display for Views UI.
   */
  function summary_title() {
    $features = spaces_features();
    if (isset($features[$this->options['spaces_feature']])) {
      return t('Feature: @feature', array(
        '@feature' => $features[$this->options['spaces_feature']]->info['name'],
      ));
    }
    return empty($this->options['spaces_feature']) ? t('Autodetect') : t('Broken');
  }

  /**
   * Override of option_definition().
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['spaces_feature'] = array(
      'default' => '',
    );
    $options['perm'] = array(
      'default' => 'access content',
    );
    return $options;
  }

  /**
   * Override of options_form().
   */
  function options_form(&$form, &$form_state) {

    // Generate feature options.
    $options = array(
      0 => t('Autodetect'),
    );
    foreach (spaces_features() as $feature) {
      $options[$feature->name] = check_plain($feature->info['name']);
    }
    $form['spaces_feature'] = array(
      '#type' => 'select',
      '#title' => t('Feature'),
      '#default_value' => $this->options['spaces_feature'],
      '#options' => $options,
      '#description' => t('Only allow access to this view if the user has access to the selected feature.'),
    );

    // Get list of permissions.
    $perms = array(
      '' => '<' . t('No permission check') . '>',
    );
    $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']);
      }
    }
    asort($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.'),
    );
  }

  /**
   * Attempt to detect the feature that this view belongs to.
   */
  protected function get_my_feature() {
    $map = features_get_component_map('views_view');
    return !empty($map[$this->view->name]) ? reset($map[$this->view->name]) : FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
spaces_plugin_access_spaces_feature::access function Check access directly. Overrides views_plugin_access::access
spaces_plugin_access_spaces_feature::get_access_callback function Provide the access check as a callback. Overrides views_plugin_access::get_access_callback
spaces_plugin_access_spaces_feature::get_my_feature protected function Attempt to detect the feature that this view belongs to.
spaces_plugin_access_spaces_feature::options_form function Override of options_form(). Overrides views_plugin_access::options_form
spaces_plugin_access_spaces_feature::option_definition function Override of option_definition(). Overrides views_plugin_access::option_definition
spaces_plugin_access_spaces_feature::summary_title function Display for Views UI. Overrides views_plugin_access::summary_title
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::query public function Add anything to the query that we might need to. 7
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_access::init public function Initialize the plugin.
views_plugin_access::options_submit public function Provide the default form form for submitting options. Overrides views_plugin::options_submit 1
views_plugin_access::options_validate public function Provide the default form form for validating options. Overrides views_plugin::options_validate 1