Commit 230cdaf1 authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1781934 by dawehner: Unify plugin_options() on the display.

parent 78e75789
......@@ -27,8 +27,6 @@ display:
type: basic
pager:
type: full
style_plugin: default
row_plugin: node
sorts:
created:
id: created
......@@ -62,6 +60,10 @@ display:
group: 0
expose:
operator: false
style:
type: default
row:
type: node
page:
id: page
display_title: Page
......
......@@ -28,10 +28,6 @@ display:
type: full
options:
items_per_page: 30
style_plugin: html_list
style_options:
type: ol
row_plugin: fields
empty:
text:
id: area
......@@ -70,6 +66,12 @@ display:
group: 0
expose:
operator: false
style:
type: html_list
options:
type: ol
row:
type: fields
page:
id: page
display_title: Page
......@@ -101,8 +103,6 @@ display:
row_options: false
arguments: false
use_more: true
style_plugin: html_list
row_plugin: fields
arguments:
nid:
id: nid
......@@ -117,3 +117,7 @@ display:
specify_validation: 1
validate:
type: node
style:
type: html_list
row:
type: fields
......@@ -30,8 +30,6 @@ display:
type: some
options:
items_per_page: 5
style_plugin: html_list
row_plugin: fields
relationships:
nid:
id: nid
......@@ -63,6 +61,10 @@ display:
field: status_extra
relationship: nid
group: 0
style:
type: html_list
row:
type: fields
page:
id: page
display_title: Page
......@@ -78,13 +80,6 @@ display:
row_plugin: false
row_options: false
fields: false
style_plugin: html_list
row_plugin: fields
row_options:
inline:
title: title
timestamp: timestamp
separator: ' '
fields:
title:
id: title
......@@ -111,6 +106,15 @@ display:
field: comment_body
label: ''
path: comments/recent
style:
type: html_list
row:
type: fields
options:
inline:
title: title
timestamp: timestamp
separator: ' '
block:
id: block
display_title: Block
......
......@@ -26,10 +26,12 @@ display:
type: basic
pager:
type: full
style_plugin: default
row_plugin: node
row_options:
links: 1
style:
type: default
row:
type: node
options:
links: 1
sorts:
sticky:
id: sticky
......@@ -82,8 +84,10 @@ display:
title: 'Front page feed'
pager:
type: some
style_plugin: rss
row_plugin: node_rss
style:
type: rss
row:
type: node_rss
path: rss.xml
displays:
default: default
......
......@@ -29,25 +29,6 @@ display:
type: full
options:
items_per_page: 36
style_plugin: table
style_options:
columns:
title: title
name: name
changed: changed
default: title
info:
title:
sortable: 1
separator: ''
name:
sortable: 1
separator: ''
changed:
sortable: 1
separator: ''
override: 1
sticky: 0
fields:
title:
id: title
......@@ -91,6 +72,26 @@ display:
id: uid
table: node
field: uid
style:
type: table
options:
columns:
title: title
name: name
changed: changed
default: title
info:
title:
sortable: 1
separator: ''
name:
sortable: 1
separator: ''
changed:
sortable: 1
separator: ''
override: 1
sticky: 0
page:
id: page
display_title: Page
......
......@@ -26,8 +26,6 @@ display:
type: basic
pager:
type: full
style_plugin: default
row_plugin: node
sorts:
sticky:
id: sticky
......@@ -75,6 +73,10 @@ display:
group: 0
expose:
operator: false
style:
type: default
row:
type: node
page:
id: page
display_title: Page
......@@ -98,9 +100,11 @@ display:
type: full
options:
items_per_page: 15
style_plugin: rss
row_plugin: node_rss
path: taxonomy/term/%/%/feed
displays:
page: page
default: 0
style:
type: rss
row:
type: node_rss
......@@ -29,39 +29,6 @@ display:
type: full
options:
items_per_page: '25'
style_plugin: table
style_options:
columns:
type: type
title: title
name: name
comment_count: comment_count
last_comment_timestamp: last_comment_timestamp
timestamp: title
new_comments: comment_count
default: last_comment_timestamp
info:
type:
sortable: 1
separator: ''
title:
sortable: 1
separator: ' '
name:
sortable: 1
separator: ''
comment_count:
sortable: 1
separator: '<br />'
last_comment_timestamp:
sortable: 1
separator: '&nbsp;'
timestamp:
separator: ''
new_comments:
separator: ''
override: 1
order: desc
relationships:
uid:
id: uid
......@@ -134,6 +101,40 @@ display:
group: 0
expose:
operator: false
style:
type: table
options:
columns:
type: type
title: title
name: name
comment_count: comment_count
last_comment_timestamp: last_comment_timestamp
timestamp: title
new_comments: comment_count
default: last_comment_timestamp
info:
type:
sortable: 1
separator: ''
title:
sortable: 1
separator: '&nbsp;'
name:
sortable: 1
separator: ''
comment_count:
sortable: 1
separator: '<br />'
last_comment_timestamp:
sortable: 1
separator: '&nbsp;'
timestamp:
separator: ''
new_comments:
separator: ''
override: 1
order: desc
page:
id: page
display_title: Page
......
......@@ -1963,15 +1963,17 @@ function views_ui_import_validate($form, &$form_state) {
continue;
}
$plugin = views_get_plugin('style', $display->getOption('style_plugin'));
$style = $display->getOption('style');
$plugin = views_get_plugin('style', $style['type']);
if (!$plugin) {
drupal_set_message(t('Style plugin @plugin is not available.', array('@plugin' => $display->getOption('style_plugin'))), 'error');
drupal_set_message(t('Style plugin @plugin is not available.', array('@plugin' => $style['type'])), 'error');
$broken = TRUE;
}
elseif ($plugin->usesRowPlugin()) {
$plugin = views_get_plugin('row', $display->getOption('row_plugin'));
$row = $display->getOption('row');
$plugin = views_get_plugin('row', $row['type']);
if (!$plugin) {
drupal_set_message(t('Row plugin @plugin is not available.', array('@plugin' => $display->getOption('row_plugin'))), 'error');
drupal_set_message(t('Row plugin @plugin is not available.', array('@plugin' => $row['type'])), 'error');
$broken = TRUE;
}
}
......@@ -2122,8 +2124,8 @@ function views_ui_edit_form_get_bucket($type, ViewExecutable $view, $display) {
break;
case 'field':
// Fetch the style plugin info so we know whether to list fields or not.
$name = $view->displayHandlers[$display['id']]->getOption('style_plugin');
$style_plugin = $view->displayHandlers[$display['id']]->getPlugin('style', $name);
$style = $view->displayHandlers[$display['id']]->getOption('style');
$style_plugin = $view->displayHandlers[$display['id']]->getPlugin('style', $style['type']);
$uses_fields = $style_plugin && $style_plugin->usesFields();
if (!$uses_fields) {
$build['fields'][] = array(
......@@ -3139,6 +3141,7 @@ function views_ui_edit_display_form($form, &$form_state) {
if (!$view->setDisplay($display_id)) {
views_ajax_error(t('Invalid display id @display', array('@display' => $display_id)));
}
$display = &$view->display[$display_id];
// Get form from the handler.
$form['options'] = array(
......@@ -4582,12 +4585,12 @@ function views_ui_config_style_form($form, &$form_state) {
$form['#section'] = $display_id . '-' . $type . '-style-options';
$plugin = views_get_plugin('style', $handler->options['style_plugin']);
$plugin = views_get_plugin('style', $handler->options['style']['type']);
if ($plugin) {
$form['style_options'] = array(
'#tree' => TRUE,
);
$plugin->init($view, $view->display[$display_id], $handler->options['style_options']);
$plugin->init($view, $view->display[$display_id], $handler->options['style']['options']);
$plugin->buildOptionsForm($form['style_options'], $form_state);
}
......
......@@ -34,16 +34,12 @@ abstract class AccessPluginBase extends PluginBase {
* @param $display
* The display handler.
*/
public function init(ViewExecutable $view, &$display) {
public function init(ViewExecutable $view, &$display, $options = NULL) {
$this->setOptionDefaults($this->options, $this->defineOptions());
$this->view = &$view;
$this->displayHandler = &$display;
if (is_object($display)) {
$options = $display->getOption('access');
// Overlay incoming options on top of defaults
$this->unpackOptions($this->options, $options);
}
$this->unpackOptions($this->options, $options);
}
/**
......
......@@ -63,16 +63,12 @@ abstract class CachePluginBase extends PluginBase {
* @param $display
* The display handler.
*/
public function init(ViewExecutable $view, &$display) {
public function init(ViewExecutable $view, &$display, $options = NULL) {
$this->setOptionDefaults($this->options, $this->defineOptions());
$this->view = &$view;
$this->displayHandler = &$display;
if (is_object($display)) {
$options = $display->getOption('cache');
// Overlay incoming options on top of defaults
$this->unpackOptions($this->options, $options);
}
$this->unpackOptions($this->options, $options);
}
/**
......
......@@ -52,8 +52,8 @@ public function init(ViewExecutable $view, &$display, $options = NULL) {
// which we don't know until init().
$row_plugins = views_fetch_plugin_names('row', $this->getStyleType(), array($view->storage->base_table));
$default_row_plugin = key($row_plugins);
if ($this->options['row_plugin'] == '') {
$this->options['row_plugin'] = $default_row_plugin;
if (empty($this->options['row']['type'])) {
$this->options['row']['type'] = $default_row_plugin;
}
}
......@@ -92,7 +92,7 @@ public function render() {
}
public function defaultableSections($section = NULL) {
if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin'))) {
if (in_array($section, array('style', 'row'))) {
return FALSE;
}
......@@ -114,14 +114,12 @@ protected function defineOptions() {
$options['displays'] = array('default' => array());
// Overrides for standard stuff:
$options['style_plugin']['default'] = 'rss';
$options['style_options']['default'] = array('description' => '');
$options['style']['contains']['type']['default'] = 'rss';
$options['style']['contains']['options']['default'] = array('description' => '');
$options['sitename_title']['default'] = FALSE;
$options['row_plugin']['default'] = '';
$options['defaults']['default']['style_plugin'] = FALSE;
$options['defaults']['default']['style_options'] = FALSE;
$options['defaults']['default']['row_plugin'] = FALSE;
$options['defaults']['default']['row_options'] = FALSE;
$options['row']['contains']['type']['default'] = '';
$options['defaults']['default']['style'] = FALSE;
$options['defaults']['default']['row'] = FALSE;
return $options;
}
......
......@@ -47,8 +47,8 @@ public function init(ViewExecutable $view, &$display, $options = NULL) {
$this->view = &$view;
$this->displayHandler = &$display;
// Overlay incoming options on top of defaults.
$this->unpackOptions($this->options, isset($options) ? $options : $display->getOption('row_options'));
// Overlay incoming options on top of defaults
$this->unpackOptions($this->options, $options);
}
/**
......
......@@ -95,10 +95,9 @@ public function init(ViewExecutable $view, &$display, $options = NULL) {
$this->view = &$view;
$this->displayHandler = &$display;
// Overlay incoming options on top of defaults
$this->unpackOptions($this->options, isset($options) ? $options : $display->getOption('style_options'));
$this->unpackOptions($this->options, $options);
if ($this->usesRowPlugin() && $display->getOption('row_plugin')) {
if ($this->usesRowPlugin() && $display->getOption('row')) {
$this->row_plugin = $display->getPlugin('row');
}
......
......@@ -609,7 +609,7 @@ protected function build_display_options($form, $form_state) {
protected function alter_display_options(&$display_options, $form, $form_state) {
foreach ($display_options as $display_type => $options) {
// Allow style plugins to hook in and provide some settings.
$style_plugin = views_get_plugin('style', $options['style_plugin']);
$style_plugin = views_get_plugin('style', $options['style']['type']);
$style_plugin->wizard_submit($form, $form_state, $this, $display_options, $display_type);
}
}
......@@ -669,8 +669,8 @@ protected function default_display_options() {
$display_options['query']['type'] = 'views_query';
$display_options['exposed_form']['type'] = 'basic';
$display_options['pager']['type'] = 'full';
$display_options['style_plugin'] = 'default';
$display_options['row_plugin'] = 'fields';
$display_options['style']['type'] = 'default';
$display_options['row']['type'] = 'fields';
// Add a least one field so the view validates and the user has a preview.
// The base field can provide a default in its base settings; otherwise,
......@@ -856,7 +856,6 @@ protected function default_display_sorts_user($form, $form_state) {
return $sorts;
}
/**
* Retrieves the page display options.
*
......@@ -873,11 +872,11 @@ protected function page_display_options(array $form, array &$form_state) {
$page = $form_state['values']['page'];
$display_options['title'] = $page['title'];
$display_options['path'] = $page['path'];
$display_options['style_plugin'] = $page['style']['style_plugin'];
$display_options['style'] = array('type' => $page['style']['style_plugin']);
// Not every style plugin supports row style plugins.
// Make sure that the selected row plugin is a valid one.
$options = $this->row_style_options();
$display_options['row_plugin'] = (isset($page['style']['row_plugin']) && isset($options[$page['style']['row_plugin']])) ? $page['style']['row_plugin'] : 'fields';
$display_options['row'] = array('type' => (isset($page['style']['row_plugin']) && isset($options[$page['style']['row_plugin']])) ? $page['style']['row_plugin'] : 'fields');
// If the specific 0 items per page, use no pager.
if (empty($page['items_per_page'])) {
......@@ -918,8 +917,8 @@ protected function block_display_options(array $form, array &$form_state) {
$display_options = array();
$block = $form_state['values']['block'];
$display_options['title'] = $block['title'];
$display_options['style_plugin'] = $block['style']['style_plugin'];
$display_options['row_plugin'] = isset($block['style']['row_plugin']) ? $block['style']['row_plugin'] : 'fields';
$display_options['style'] = array('type' => $block['style']['style_plugin']);
$display_options['row'] = array('type' => isset($block['style']['row_plugin']) ? $block['style']['row_plugin'] : 'fields');
$display_options['pager']['type'] = $block['pager'] ? 'full' : (empty($block['items_per_page']) ? 'none' : 'some');
$display_options['pager']['options']['items_per_page'] = $block['items_per_page'];
return $display_options;
......@@ -939,8 +938,8 @@ protected function block_display_options(array $form, array &$form_state) {
protected function page_feed_display_options($form, $form_state) {
$display_options = array();
$display_options['pager']['type'] = 'some';
$display_options['style_plugin'] = 'rss';
$display_options['row_plugin'] = $form_state['values']['page']['feed_properties']['row_plugin'];
$display_options['style'] = array('type' => 'rss');
$display_options['row'] = array('type' => $form_state['values']['page']['feed_properties']['row_plugin']);
$display_options['path'] = $form_state['values']['page']['feed_properties']['path'];
$display_options['title'] = $form_state['values']['page']['title'];
$display_options['displays'] = array(
......@@ -971,8 +970,6 @@ protected function page_feed_display_options($form, $form_state) {
*/
protected function setDefaultOptions($options, DisplayPluginBase $display, DisplayPluginBase $default_display) {
foreach ($options as $option => $value) {
// @todo: Wouldn't it be possible to call set_override and set_option
// instead.
// If the default display supports this option, set the value there.
// Otherwise, set it on the provided display.
$default_value = $default_display->getOption($option);
......
......@@ -72,7 +72,8 @@ public function testCommentWizard() {
$view = views_get_view($view['name']);
$view->initDisplay();
$view->initHandlers();
$this->assertEqual($view->display_handler->getOption('row_plugin'), 'comment');
$row = $view->display_handler->getOption('row');
$this->assertEqual($row['type'], 'comment');
// Check for the default filters.
$this->assertEqual($view->filter['status']->table, 'comment');
......
......@@ -69,7 +69,7 @@ function testAccessPerm() {
function testAccessRole() {
$view = $this->createViewFromConfig('test_access_role');
$view->displayHandlers['default']->options['access']['role'] = array(
$view->displayHandlers['default']->options['access']['options']['role'] = array(
$this->normal_role => $this->normal_role,
);
......
......@@ -88,8 +88,10 @@ function testTimeCaching() {
$view = $this->getView();
$view->display_handler->overrideOption('cache', array(
'type' => 'time',
'results_lifespan' => '3600',
'output_lifespan' => '3600',
'options' => array(
'results_lifespan' => '3600',
'output_lifespan' => '3600'
)
));
$this->executeView($view);
......@@ -108,8 +110,10 @@ function testTimeCaching() {
$view = $this->getView();
$view->display_handler->overrideOption('cache', array(
'type' => 'time',
'results_lifespan' => '3600',
'output_lifespan' => '3600',
'options' => array(
'results_lifespan' => '3600',
'output_lifespan' => '3600'
)
));
$this->executeView($view);
......@@ -127,6 +131,7 @@ function testNoneCaching() {
$view = $this->getView();
$view->display_handler->overrideOption('cache', array(
'type' => 'none',
'options' => array()
));
$this->executeView($view);
......@@ -146,6 +151,7 @@ function testNoneCaching() {
$view = $this->getView();
$view->display_handler->overrideOption('cache', array(
'type' => 'none',
'options' => array()
));
$this->executeView($view);
......@@ -164,7 +170,9 @@ function testHeaderStorage() {
$view->storage->name = 'test_cache_header_storage';
$view->display_handler->overrideOption('cache', array(
'type' => 'time',