View source
<?php
class spaces_plugin_access_spaces_feature extends views_plugin_access {
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);
}
function get_access_callback() {
$feature = $this->options['spaces_feature'] == 0 ? $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,
),
);
}
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 $this->options['spaces_feature'] == 0 ? t('Autodetect') : t('Broken');
}
function option_definition() {
$options = parent::option_definition();
$options['spaces_feature'] = array(
'default' => 0,
);
$options['perm'] = array(
'default' => 'access content',
);
return $options;
}
function options_form(&$form, &$form_state) {
$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.'),
);
$perms = array(
'' => '<' . t('No permission check') . '>',
);
foreach (module_implements('permission') as $module) {
if ($permissions = module_invoke($module, 'permission')) {
$module_perms = array();
foreach ($permissions as $key => $data) {
$module_perms[$key] = check_plain($data['title']);
}
$perms[$module] = $module_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.'),
);
}
protected function get_my_feature() {
$map = features_get_component_map('views');
return !empty($map[$this->view->name]) ? reset($map[$this->view->name]) : FALSE;
}
}