Commit 5a6647be authored by webchick's avatar webchick

Issue #1964348 by damiankloip, xjm, dawehner: Rename...

Issue #1964348 by damiankloip, xjm, dawehner: Rename DisplayPluginBase::getStylePlugin() and enable type filtering for more plugin types.
parent b2e49105
......@@ -21,7 +21,7 @@
* help = @Translation("Display the comment with standard comment view."),
* base = {"comment"},
* entity_type = "comment",
* type = "normal"
* display_types = {"normal"}
* )
*/
class CommentRow extends EntityRow {
......
......@@ -21,7 +21,7 @@
* help = @Translation("Display the comment as RSS."),
* theme = "views_view_row_rss",
* base = {"comment"},
* type = "feed"
* display_types = {"feed"}
* )
*/
class Rss extends RowPluginBase {
......
......@@ -82,9 +82,9 @@ public function optionsSummary(&$categories, &$options) {
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getStyleType().
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getType().
*/
protected function getStyleType() {
protected function getType() {
return 'entity_reference';
}
......
......@@ -21,7 +21,7 @@
* title = @Translation("Entity Reference inline fields"),
* help = @Translation("Displays the fields with an optional template."),
* theme = "views_view_fields",
* type = "entity_reference"
* display_types = {"entity_reference"}
* )
*/
class EntityReference extends Fields {
......
......@@ -21,7 +21,7 @@
* title = @Translation("Entity Reference list"),
* help = @Translation("Returns results as a PHP array of labels and rendered rows."),
* theme = "views_view_unformatted",
* type = "entity_reference"
* display_types = {"entity_reference"}
* )
*/
class EntityReference extends StylePluginBase {
......
......@@ -26,7 +26,7 @@
* help = @Translation("Display the content with standard node view."),
* base = {"node"},
* entity_type = "node",
* type = "normal"
* display_types = {"normal"}
* )
*/
class NodeRow extends EntityRow {
......
......@@ -21,7 +21,7 @@
* help = @Translation("Display the content with standard node view."),
* theme = "views_view_row_rss",
* base = {"node"},
* type = "feed",
* display_types = {"feed"},
* module = "node"
* )
*/
......
......@@ -83,9 +83,9 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getStyleType().
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getType().
*/
protected function getStyleType() {
protected function getType() {
return 'data';
}
......
......@@ -22,7 +22,7 @@
* module = "rest",
* title = @Translation("Entity"),
* help = @Translation("Use entities as row data."),
* type = "data"
* display_types = {"data"}
* )
*/
class DataEntityRow extends RowPluginBase {
......
......@@ -23,7 +23,7 @@
* module = "rest",
* title = @Translation("Fields"),
* help = @Translation("Use fields as row data."),
* type = "data"
* display_types = {"data"}
* )
*/
class DataFieldRow extends RowPluginBase {
......
......@@ -23,7 +23,7 @@
* module = "rest",
* title = @Translation("Serializer"),
* help = @Translation("Serializes views row data using the Serializer component."),
* type = "data"
* display_types = {"data"}
* )
*/
class Serializer extends StylePluginBase {
......
......@@ -23,7 +23,7 @@
* help = @Translation("Display the user with standard user view."),
* base = {"users"},
* entity_type = "user",
* type = "normal"
* display_types = {"normal"}
* )
*/
class UserRow extends EntityRow {
......
......@@ -567,7 +567,7 @@ function default_summary_form(&$form, &$form_state) {
$summary_plugins = array();
$format_options = array();
foreach ($style_plugins as $key => $plugin) {
if (isset($plugin['type']) && $plugin['type'] == 'summary') {
if (isset($plugin['display_types']) && in_array('summary', $plugin['display_types'])) {
$summary_plugins[$key] = $plugin;
$format_options[$key] = $plugin['title'];
}
......
......@@ -1472,7 +1472,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$access = $this->getOption('access');
$form['access']['type'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('access', NULL, array($this->view->storage->get('base_table'))),
'#options' => views_fetch_plugin_names('access', $this->getType(), array($this->view->storage->get('base_table'))),
'#default_value' => $access['type'],
);
......@@ -1507,7 +1507,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$cache = $this->getOption('cache');
$form['cache']['type'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('cache', NULL, array($this->view->storage->get('base_table'))),
'#options' => views_fetch_plugin_names('cache', $this->getType(), array($this->view->storage->get('base_table'))),
'#default_value' => $cache['type'],
);
......@@ -1598,7 +1598,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$style_plugin = $this->getPlugin('style');
$form['style'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('style', $this->getStyleType(), array($this->view->storage->get('base_table'))),
'#options' => views_fetch_plugin_names('style', $this->getType(), array($this->view->storage->get('base_table'))),
'#default_value' => $style_plugin->definition['id'],
'#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.'),
);
......@@ -1640,7 +1640,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$row_plugin_instance = $this->getPlugin('row');
$form['row'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('row', $this->getStyleType(), array($this->view->storage->get('base_table'))),
'#options' => views_fetch_plugin_names('row', $this->getType(), array($this->view->storage->get('base_table'))),
'#default_value' => $row_plugin_instance->definition['id'],
);
......@@ -1955,7 +1955,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$exposed_form = $this->getOption('exposed_form');
$form['exposed_form']['type'] = array(
'#type' => 'radios',
'#options' => views_fetch_plugin_names('exposed_form', NULL, array($this->view->storage->get('base_table'))),
'#options' => views_fetch_plugin_names('exposed_form', $this->getType(), array($this->view->storage->get('base_table'))),
'#default_value' => $exposed_form['type'],
);
......@@ -2553,10 +2553,21 @@ function preview() {
}
/**
* Displays can require a certain type of style plugin. By default, they will
* be 'normal'.
* Returns the display type that this display requires.
*
* This can be used for filtering views plugins. E.g. if a plugin category of
* 'foo' is specified, only plugins with no 'types' declared or 'types'
* containing 'foo'. If you have a type of bar, this plugin will not be used.
* This is applicable for style, row, access, cache, and exposed_form plugins.
*
* @return string
* The required display type. Defaults to 'normal'.
*
* @see views_fetch_plugin_names()
*/
protected function getStyleType() { return 'normal'; }
protected function getType() {
return 'normal';
}
/**
* Make sure the display and all associated handlers are valid.
......
......@@ -51,7 +51,7 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio
// Set the default row style. Ideally this would be part of the option
// definition, but in this case it's dependent on the view's base table,
// which we don't know until init().
$row_plugins = views_fetch_plugin_names('row', $this->getStyleType(), array($view->storage->get('base_table')));
$row_plugins = views_fetch_plugin_names('row', $this->getType(), array($view->storage->get('base_table')));
$default_row_plugin = key($row_plugins);
if (empty($this->options['row']['type'])) {
$this->options['row']['type'] = $default_row_plugin;
......@@ -59,9 +59,9 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getStyleType().
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getType().
*/
protected function getStyleType() {
protected function getType() {
return 'feed';
}
......
......@@ -21,7 +21,7 @@
* id = "none",
* title = @Translation("Display all items"),
* help = @Translation("Display all items that this view might find."),
* type = "basic"
* display_types = {"basic"}
* )
*/
class None extends PagerPluginBase {
......
......@@ -19,7 +19,7 @@
* id = "some",
* title = @Translation("Display a specified number of items"),
* help = @Translation("Display a limited number items that this view might find."),
* type = "basic"
* display_types = {"basic"}
* )
*/
class Some extends PagerPluginBase {
......
......@@ -23,7 +23,7 @@
* title = @Translation("Fields"),
* help = @Translation("Displays the fields with an optional template."),
* theme = "views_view_fields",
* type = "normal"
* display_types = {"normal"}
* )
*/
class Fields extends RowPluginBase {
......
......@@ -18,7 +18,7 @@
* title = @Translation("Fields"),
* help = @Translation("Display fields as RSS items."),
* theme = "views_view_row_rss",
* type = "feed"
* display_types = {"feed"}
* )
*/
class RssFields extends RowPluginBase {
......
......@@ -21,7 +21,7 @@
* title = @Translation("Unformatted list"),
* help = @Translation("Displays rows one after another."),
* theme = "views_view_unformatted",
* type = "normal"
* display_types = {"normal"}
* )
*/
class DefaultStyle extends StylePluginBase {
......
......@@ -21,7 +21,7 @@
* title = @Translation("List"),
* help = @Translation("Displays the default summary as a list."),
* theme = "views_view_summary",
* type = "summary"
* display_types = {"summary"}
* )
*/
class DefaultSummary extends StylePluginBase {
......
......@@ -20,7 +20,7 @@
* title = @Translation("Grid"),
* help = @Translation("Displays rows in a grid."),
* theme = "views_view_grid",
* type = "normal"
* display_types = {"normal"}
* )
*/
class Grid extends StylePluginBase {
......
......@@ -20,7 +20,7 @@
* title = @Translation("HTML List"),
* help = @Translation("Displays rows as HTML list."),
* theme = "views_view_list",
* type = "normal"
* display_types = {"normal"}
* )
*/
class HtmlList extends StylePluginBase {
......
......@@ -20,7 +20,7 @@
* title = @Translation("RSS Feed"),
* help = @Translation("Generates an RSS feed from a view."),
* theme = "views_view_rss",
* type = "feed"
* display_types = {"feed"}
* )
*/
class Rss extends StylePluginBase {
......
......@@ -21,7 +21,7 @@
* title = @Translation("Table"),
* help = @Translation("Displays rows in a table."),
* theme = "views_view_table",
* type = "normal"
* display_types = {"normal"}
* )
*/
class Table extends StylePluginBase {
......
......@@ -20,7 +20,7 @@
* title = @Translation("Unformatted"),
* help = @Translation("Displays the summary unformatted, with option for one after another or inline."),
* theme = "views_view_summary_unformatted",
* type = "summary"
* display_types = {"summary"}
* )
*/
class UnformattedSummary extends DefaultSummary {
......
......@@ -144,6 +144,30 @@ function testStatusFunctions() {
$this->assertEqual(!$view->status(), views_view_is_disabled($view), 'views_view_is_disabled is correct.');
}
/**
* Tests the views_fetch_plugin_names() function.
*/
public function testViewsFetchPluginNames() {
// All style plugins should be returned, as we have not specified a type.
$plugins = views_fetch_plugin_names('style');
$definitions = Views::pluginManager('style')->getDefinitions();
$expected = array();
foreach ($definitions as $id =>$definition) {
$expected[$id] = $definition['title'];
}
asort($expected);
$this->assertIdentical(array_keys($plugins), array_keys($expected));
// Test using the 'test' style plugin type only returns the test_style and
// mapping_test plugins.
$plugins = views_fetch_plugin_names('style', 'test');
$this->assertIdentical(array_keys($plugins), array('mapping_test', 'test_style'));
// Test a non existent style plugin type returns no plugins.
$plugins = views_fetch_plugin_names('style', $this->randomString());
$this->assertIdentical($plugins, array());
}
/**
* Helper to return an expected views option array.
*
......
......@@ -30,6 +30,13 @@ class DisplayTest extends DisplayPluginBase {
*/
protected $usesAttachments = TRUE;
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getType().
*/
protected function getType() {
return 'test';
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::defineOptions().
*/
......
......@@ -21,7 +21,7 @@
* title = @Translation("Test row plugin"),
* help = @Translation("Provides a generic row test plugin."),
* theme = "views_view_row_test",
* type = "normal"
* display_types = {"normal", "test"}
* )
*/
class RowTest extends RowPluginBase {
......
......@@ -22,7 +22,7 @@
* title = @Translation("Field mapping"),
* help = @Translation("Maps specific fields to specific purposes."),
* theme = "views_view_mapping_test",
* type = "normal"
* display_types = {"normal", "test"}
* )
*/
class MappingTest extends Mapping {
......
......@@ -21,7 +21,7 @@
* title = @Translation("Test style plugin"),
* help = @Translation("Provides a generic style test plugin."),
* theme = "views_view_style_test",
* type = "normal"
* display_types = {"normal", "test"}
* )
*/
class StyleTest extends StylePluginBase {
......
......@@ -955,13 +955,8 @@ function views_fetch_plugin_names($type, $key = NULL, $base = array()) {
$plugins = array();
foreach ($definitions as $id => $plugin) {
// Skip plugins that don't conform to our key.
if ($key && (empty($plugin['type']) || $plugin['type'] != $key)) {
continue;
}
// @todo While Views is providing on behalf of core modules, check to see
// if they are enabled or not.
if (isset($plugin['module']) && !\Drupal::moduleHandler()->moduleExists($plugin['module'])) {
// Skip plugins that don't conform to our key, if they have one.
if ($key && isset($plugin['display_types']) && !in_array($key, $plugin['display_types'])) {
continue;
}
......@@ -975,8 +970,7 @@ function views_fetch_plugin_names($type, $key = NULL, $base = array()) {
return $plugins;
}
// fall-through
return array();
return $plugins;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment