Issue #1744186 by damiankloip, tim.plunkett: Move uses_options() from plugin annotation to a class property.

8.0.x
Tim Plunkett 2012-08-23 16:29:26 +02:00
parent 53c7d23519
commit e6bddaea6e
32 changed files with 86 additions and 59 deletions

View File

@ -46,6 +46,13 @@ abstract class PluginBase extends ComponentPluginBase {
*/
public $localization_keys;
/**
* Denotes whether the plugin has an additional options form.
*
* @var bool
*/
public $usesOptions = FALSE;
/**
* Constructs a Plugin object.
*/
@ -452,4 +459,11 @@ abstract class PluginBase extends ComponentPluginBase {
return check_plain($this->definition['title']);
}
/**
* Returns the usesOptions property.
*/
function usesOptions() {
return $this->usesOptions;
}
}

View File

@ -19,12 +19,16 @@ use Drupal\Core\Annotation\Translation;
* id = "perm",
* title = @Translation("Permission"),
* help = @Translation("Access will be granted to users with the specified permission string."),
* help_topic = "access-perm",
* uses_options = TRUE
* help_topic = "access-perm"
* )
*/
class Permission extends AccessPluginBase {
/**
* Overrides Drupal\views\Plugin\Plugin::$usesOptions.
*/
public $usesOptions = TRUE;
function access($account) {
return views_check_perm($this->options['perm'], $account);
}

View File

@ -19,12 +19,16 @@ use Drupal\Core\Annotation\Translation;
* id = "role",
* title = @Translation("Role"),
* help = @Translation("Access will be granted to users with any of the specified roles."),
* help_topic = "access-role",
* uses_options = TRUE
* help_topic = "access-role"
* )
*/
class Role extends AccessPluginBase {
/**
* Overrides Drupal\views\Plugin\Plugin::$usesOptions.
*/
public $usesOptions = TRUE;
function access($account) {
return views_check_roles(array_filter($this->options['role']), $account);
}

View File

@ -678,10 +678,10 @@ abstract class ArgumentPluginBase extends HandlerBase {
);
foreach ($summary_plugins as $id => $info) {
if (empty($info['uses_options'])) {
$plugin = $this->get_plugin('style', $id);
if (!$plugin->usesOptions()) {
continue;
}
$plugin = $this->get_plugin('style', $id);
if ($plugin) {
$form['summary']['options'][$id] = array(
'#prefix' => '<div id="edit-options-summary-options-' . $id . '-wrapper">',

View File

@ -19,12 +19,16 @@ use Drupal\Core\Annotation\Translation;
* id = "time",
* title = @Translation("Time-based"),
* help = @Translation("Simple time-based caching of data."),
* help_topic = "cache-time",
* uses_options = TRUE
* help_topic = "cache-time"
* )
*/
class Time extends CachePluginBase {
/**
* Overrides Drupal\views\Plugin\Plugin::$usesOptions.
*/
public $usesOptions = TRUE;
function option_definition() {
$options = parent::option_definition();
$options['results_lifespan'] = array('default' => 3600);

View File

@ -44,6 +44,11 @@ abstract class DisplayPluginBase extends PluginBase {
*/
var $extender = array();
/**
* Overrides Drupal\views\Plugin\Plugin::$usesOptions.
*/
public $usesOptions = TRUE;
/**
* Stores the rendered output of the display.
*
@ -1209,7 +1214,7 @@ abstract class DisplayPluginBase extends PluginBase {
);
// This adds a 'Settings' link to the style_options setting if the style has options.
if (!empty($style_plugin['uses_options'])) {
if ($style_plugin_instance->usesOptions()) {
$options['style_plugin']['links']['style_options'] = t('Change settings for this format');
}
@ -1228,7 +1233,7 @@ abstract class DisplayPluginBase extends PluginBase {
'desc' => t('Change the way each row in the view is styled.'),
);
// This adds a 'Settings' link to the row_options setting if the row style has options.
if (!empty($row_plugin['uses_options'])) {
if ($row_plugin_instance->usesOptions()) {
$options['row_plugin']['links']['row_options'] = t('Change settings for this style');
}
}
@ -1278,7 +1283,7 @@ abstract class DisplayPluginBase extends PluginBase {
$options['pager']['title'] = t('Items to display');
}
if (!empty($pager_plugin->definition['uses_options'])) {
if ($pager_plugin->usesOptions()) {
$options['pager']['links']['pager_options'] = t('Change settings for this pager type.');
}
@ -1340,7 +1345,7 @@ abstract class DisplayPluginBase extends PluginBase {
'desc' => t('Specify access control type for this display.'),
);
if (!empty($access_plugin->definition['uses_options'])) {
if ($access_plugin->usesOptions()) {
$options['access']['links']['access_options'] = t('Change settings for this access type.');
}
@ -1360,11 +1365,11 @@ abstract class DisplayPluginBase extends PluginBase {
'desc' => t('Specify caching type for this display.'),
);
if (!empty($cache_plugin->definition['uses_options'])) {
if ($cache_plugin->usesOptions()) {
$options['cache']['links']['cache_options'] = t('Change settings for this caching type.');
}
if (!empty($access_plugin->definition['uses_options'])) {
if ($access_plugin->usesOptions()) {
$options['access']['links']['access_options'] = t('Change settings for this access type.');
}
@ -1405,7 +1410,7 @@ abstract class DisplayPluginBase extends PluginBase {
'desc' => t('Select the kind of exposed filter to use.'),
);
if (!empty($exposed_form_plugin->definition['uses_options'])) {
if ($exposed_form_plugin->usesOptions()) {
$options['exposed_form']['links']['exposed_form_options'] = t('Exposed form settings for this exposed form style.');
}
@ -1586,8 +1591,8 @@ abstract class DisplayPluginBase extends PluginBase {
'#default_value' => $access['type'],
);
$access_plugin = views_fetch_plugin_data('access', $access['type']);
if (!empty($access_plugin['uses_options'])) {
$access_plugin = $this->get_plugin('access');
if ($access_plugin->usesOptions()) {
$form['markup'] = array(
'#prefix' => '<div class="form-item description">',
'#markup' => t('You may also adjust the !settings for the currently selected access restriction.', array('!settings' => $this->option_link(t('settings'), 'access_options'))),
@ -1629,8 +1634,8 @@ abstract class DisplayPluginBase extends PluginBase {
'#default_value' => $cache['type'],
);
$cache_plugin = views_fetch_plugin_data('cache', $cache['type']);
if (!empty($cache_plugin['uses_options'])) {
$cache_plugin = $this->get_plugin('cache');
if ($cache_plugin->usesOptions()) {
$form['markup'] = array(
'#prefix' => '<div class="form-item description">',
'#suffix' => '</div>',
@ -1738,8 +1743,8 @@ abstract class DisplayPluginBase extends PluginBase {
'#description' => t('If the style you choose has settings, be sure to click the settings button that will appear next to it in the View summary.'),
);
$style_plugin = $manager->getDefinition($this->get_option('style_plugin'));
if (!empty($style_plugin['uses_options'])) {
$style_plugin = $this->get_plugin('style');
if ($style_plugin->usesOptions()) {
$form['markup'] = array(
'#markup' => '<div class="form-item description">' . t('You may also adjust the !settings for the currently selected style.', array('!settings' => $this->option_link(t('settings'), 'style_options'))) . '</div>',
);
@ -1782,8 +1787,8 @@ abstract class DisplayPluginBase extends PluginBase {
'#default_value' => $this->get_option('row_plugin'),
);
$row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin'));
if (!empty($row_plugin['uses_options'])) {
$row_plugin = $this->get_plugin('row');
if ($row_plugin->usesOptions()) {
$form['markup'] = array(
'#markup' => '<div class="form-item description">' . t('You may also adjust the !settings for the currently selected row style.', array('!settings' => $this->option_link(t('settings'), 'row_options'))) . '</div>',
);
@ -2137,8 +2142,8 @@ abstract class DisplayPluginBase extends PluginBase {
'#default_value' => $exposed_form['type'],
);
$exposed_form_plugin = views_fetch_plugin_data('exposed_form', $exposed_form['type']);
if (!empty($exposed_form_plugin['uses_options'])) {
$exposed_form_plugin = $this->get_plugin('exposed_form');
if ($exposed_form_plugin->usesOptions()) {
$form['markup'] = array(
'#prefix' => '<div class="form-item description">',
'#suffix' => '</div>',
@ -2173,8 +2178,8 @@ abstract class DisplayPluginBase extends PluginBase {
'#default_value' => $pager['type'],
);
$pager_plugin = views_fetch_plugin_data('pager', $pager['type'], array($this->view->base_table));
if (!empty($pager_plugin['uses_options'])) {
$pager_plugin = $this->get_plugin('pager');
if ($pager_plugin->usesOptions()) {
$form['markup'] = array(
'#prefix' => '<div class="form-item description">',
'#suffix' => '</div>',
@ -2333,7 +2338,7 @@ abstract class DisplayPluginBase extends PluginBase {
if ($plugin) {
$access = array('type' => $form_state['values']['access']['type']);
$this->set_option('access', $access);
if (!empty($plugin->definition['uses_options'])) {
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('access_options'));
}
}
@ -2354,7 +2359,7 @@ abstract class DisplayPluginBase extends PluginBase {
if ($plugin) {
$cache = array('type' => $form_state['values']['cache']['type']);
$this->set_option('cache', $cache);
if (!empty($plugin->definition['uses_options'])) {
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('cache_options'));
}
}
@ -2412,7 +2417,7 @@ abstract class DisplayPluginBase extends PluginBase {
$this->set_option('row_options', array());
// send ajax form to options page if we use it.
if (!empty($plugin->definition['uses_options'])) {
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('row_options'));
}
}
@ -2427,7 +2432,7 @@ abstract class DisplayPluginBase extends PluginBase {
$this->set_option($section, $form_state['values'][$section]);
$this->set_option('style_options', array());
// send ajax form to options page if we use it.
if (!empty($plugin->definition['uses_options'])) {
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('style_options'));
}
}
@ -2453,7 +2458,7 @@ abstract class DisplayPluginBase extends PluginBase {
if ($plugin) {
$exposed_form = array('type' => $form_state['values']['exposed_form']['type'], 'options' => array());
$this->set_option('exposed_form', $exposed_form);
if (!empty($plugin->definition['uses_options'])) {
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('exposed_form_options'));
}
}
@ -2480,7 +2485,7 @@ abstract class DisplayPluginBase extends PluginBase {
$pager = array('type' => $form_state['values']['pager']['type'], 'options' => $plugin->options);
$this->set_option('pager', $pager);
if (!empty($plugin->definition['uses_options'])) {
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('pager_options'));
}
}

View File

@ -19,7 +19,6 @@ use Drupal\Core\Annotation\Translation;
* id = "basic",
* title = @Translation("Basic"),
* help = @Translation("Basic exposed form"),
* uses_options = TRUE,
* help_topic = "exposed-form-basic"
* )
*/

View File

@ -24,6 +24,11 @@ use Drupal\views\Plugin\views\PluginBase;
*/
abstract class ExposedFormPluginBase extends PluginBase {
/**
* Overrides Drupal\views\Plugin\Plugin::$usesOptions.
*/
public $usesOptions = TRUE;
/**
* Initialize the plugin.
*

View File

@ -19,7 +19,6 @@ use Drupal\Core\Annotation\Translation;
* id = "input_required",
* title = @Translation("Input required"),
* help = @Translation("An exposed form that only renders a view if the form contains user input."),
* uses_options = TRUE,
* help_topic = "exposed-form-input-required"
* )
*/

View File

@ -20,8 +20,7 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Paged output, full pager"),
* short_title = @Translation("Full"),
* help = @Translation("Paged output, full Drupal style"),
* help_topic = "pager-full",
* uses_options = TRUE
* help_topic = "pager-full"
* )
*/
class Full extends PagerPluginBase {

View File

@ -20,8 +20,7 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Paged output, mini pager"),
* short_title = @Translation("Mini"),
* help = @Translation("Use the mini pager output."),
* help_topic = "pager-mini",
* uses_options = TRUE
* help_topic = "pager-mini"
* )
*/
class Mini extends PagerPluginBase {

View File

@ -20,7 +20,6 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Display all items"),
* help = @Translation("Display all items that this view might find."),
* help_topic = "pager-none",
* uses_options = TRUE,
* type = "basic"
* )
*/

View File

@ -26,6 +26,11 @@ abstract class PagerPluginBase extends PluginBase {
var $total_items = 0;
/**
* Overrides Drupal\views\Plugin\Plugin::$usesOptions.
*/
public $usesOptions = TRUE;
/**
* Initialize the plugin.
*

View File

@ -20,7 +20,6 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("Display a specified number of items"),
* help = @Translation("Display a limited number items that this view might find."),
* help_topic = "pager-some",
* uses_options = TRUE,
* type = "basic"
* )
*/

View File

@ -24,7 +24,6 @@ use Drupal\Core\Annotation\Translation;
* help = @Translation("Displays the fields with an optional template."),
* theme = "views_view_fields",
* uses_fields = TRUE,
* uses_options = TRUE,
* type = "normal",
* help_topic = "style-row-fields"
* )

View File

@ -26,6 +26,11 @@ use Drupal\views\Plugin\views\PluginBase;
*/
abstract class RowPluginBase extends PluginBase {
/**
* Overrides Drupal\views\Plugin\Plugin::$usesOptions.
*/
public $usesOptions = TRUE;
/**
* Initialize the row plugin.
*/

View File

@ -19,7 +19,6 @@ use Drupal\Core\Annotation\Translation;
* help = @Translation("Display fields as RSS items."),
* theme = "views_view_row_rss",
* uses_fields = TRUE,
* uses_options = TRUE,
* type = "feed",
* help_topic = "style-row-fields"
* )

View File

@ -24,7 +24,6 @@ use Drupal\Core\Annotation\Translation;
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* uses_grouping = TRUE,
* uses_options = TRUE,
* type = "normal",
* help_topic = "style-unformatted"
* )

View File

@ -22,7 +22,6 @@ use Drupal\Core\Annotation\Translation;
* help = @Translation("Displays the default summary as a list."),
* theme = "views_view_summary",
* type = "summary",
* uses_options = TRUE,
* help_topic = "style-summary"
* )
*/

View File

@ -23,7 +23,6 @@ use Drupal\Core\Annotation\Translation;
* uses_fields = FALSE,
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* uses_options = TRUE,
* type = "normal",
* help_topic = "style-grid"
* )

View File

@ -22,7 +22,6 @@ use Drupal\Core\Annotation\Translation;
* theme = "views_view_list",
* uses_row_plugin = TRUE,
* uses_row_class = TRUE,
* uses_options = TRUE,
* type = "normal",
* help_topic = "style-list"
* )

View File

@ -21,7 +21,6 @@ use Drupal\Core\Annotation\Translation;
* help = @Translation("Generates an RSS feed from a view."),
* theme = "views_view_rss",
* uses_row_plugin = TRUE,
* uses_options = TRUE,
* type = "feed",
* help_topic = "style-rss"
* )

View File

@ -30,6 +30,11 @@ use Drupal\Core\Annotation\Translation;
*/
abstract class StylePluginBase extends PluginBase {
/**
* Overrides Drupal\views\Plugin\Plugin::$usesOptions.
*/
public $usesOptions = TRUE;
/**
* Store all available tokens row rows.
*/

View File

@ -23,7 +23,6 @@ use Drupal\Core\Annotation\Translation;
* uses_row_plugin = FALSE,
* uses_row_class = TRUE,
* uses_fields = TRUE,
* uses_options = TRUE,
* type = "normal",
* help_topic = "style-table"
* )

View File

@ -21,7 +21,6 @@ use Drupal\Core\Annotation\Translation;
* help = @Translation("Displays the summary unformatted, with option for one after another or inline."),
* theme = "views_view_summary_unformatted",
* type = "summary",
* uses_options = TRUE,
* help_topic = "style-summary-unformatted"
* )
*/

View File

@ -20,7 +20,6 @@ use Drupal\Core\Annotation\Translation;
* theme = "views_view_row_rss",
* title = @Translation("Aggregator item"),
* help = @Translation("Display the aggregator item using the data from the original source."),
* uses_options = TRUE,
* type = "feed",
* help_topic = "style-aggregator-rss"
* )

View File

@ -21,7 +21,6 @@ use Drupal\Core\Annotation\Translation;
* help = @Translation("Display the comment as RSS."),
* theme = "views_view_row_rss",
* base = {"comment"},
* uses_options = TRUE,
* type = "feed",
* help_topic = "style-comment-rss"
* )

View File

@ -21,7 +21,6 @@ use Drupal\Core\Annotation\Translation;
* help = @Translation("Display the comment with standard comment view."),
* theme = "views_view_row_comment",
* base = {"comment"},
* uses_options = TRUE,
* type = "normal",
* help_topic = "style-comment"
* )

View File

@ -22,7 +22,6 @@ use stdClass;
* help = @Translation("Display the content with standard node view."),
* theme = "views_view_row_rss",
* base = {"node"},
* uses_options = TRUE,
* type = "feed",
* module = "node",
* help_topic = "style-node-rss"

View File

@ -24,7 +24,6 @@ use Drupal\views\Plugin\views\row\RowPluginBase;
* title = @Translation("Content"),
* help = @Translation("Display the content with standard node view."),
* base = {"node"},
* uses_options = TRUE,
* type = "normal",
* help_topic = "style-node"
* )

View File

@ -22,7 +22,6 @@ use Drupal\Core\Annotation\Translation;
* title = @Translation("User"),
* help = @Translation("Display the user with standard user view."),
* base = {"users"},
* uses_options = TRUE,
* type = "normal",
* help_topic = "style-users"
* )

View File

@ -247,7 +247,6 @@
* 'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
* 'theme' => 'views_view_row_node',
* 'base' => array('node'), // only works with 'node' as base.
* 'uses_options' => TRUE,
* 'type' => 'normal',
* ),
* @endcode
@ -537,8 +536,6 @@ function hook_views_data_alter(&$data) {
* perspective.
* - no_ui: Set to TRUE to denote that the plugin doesn't appear to be
* selectable in the ui, though on the api side they still exists.
* - uses_options: Set to TRUE to denote that the plugin has an additional
* options form.
* - help: A short help text, wrapped in t() used as description on the plugin settings form.
* - help topic: The name of an entry by advanced help for the plugin.
* - theme: The name of a theme suggestion to use for the display.