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,9 +26,11 @@ display:
type: basic
pager:
type: full
style_plugin: default
row_plugin: node
row_options:
style:
type: default
row:
type: node
options:
links: 1
sorts:
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,17 +34,13 @@ 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);
}
}
/**
* Retrieve the options when this is a new access
......
......@@ -63,17 +63,13 @@ 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);
}
}
/**
* Return a string to display as the clickable title for the
......
......@@ -352,10 +352,8 @@ public function attachTo($display_id) { }
*/
public function defaultableSections($section = NULL) {
$sections = array(
'access' => array('access', 'access_options'),
'access_options' => array('access', 'access_options'),
'cache' => array('cache', 'cache_options'),
'cache_options' => array('cache', 'cache_options'),
'access' => array('access'),
'cache' => array('cache'),
'title' => array('title'),
'css_class' => array('css_class'),
'use_ajax' => array('use_ajax'),
......@@ -369,10 +367,8 @@ public function defaultableSections($section = NULL) {
'link_display' => array('link_display', 'link_url'),
// Force these to cascade properly.
'style_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
'style_options' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
'row_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
'row_options' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'),
'style' => array('style', 'row'),
'row' => array('style', 'row'),
'pager' => array('pager', 'pager_options'),
'pager_options' => array('pager', 'pager_options'),
......@@ -427,21 +423,17 @@ protected function defineOptions() {
'hide_attachment_summary' => TRUE,
'hide_admin_links' => FALSE,
'pager' => TRUE,
'pager_options' => TRUE,
'use_more' => TRUE,
'use_more_always' => TRUE,
'use_more_text' => TRUE,
'exposed_form' => TRUE,
'exposed_form_options' => TRUE,
'link_display' => TRUE,
'link_url' => '',
'group_by' => TRUE,
'style_plugin' => TRUE,
'style_options' => TRUE,
'row_plugin' => TRUE,
'row_options' => TRUE,
'style' => TRUE,
'row' => TRUE,
'header' => TRUE,
'footer' => TRUE,
......@@ -523,11 +515,13 @@ protected function defineOptions() {
'access' => array(
'contains' => array(
'type' => array('default' => 'none'),
'options' => array('default' => array()),
),
),
'cache' => array(
'contains' => array(
'type' => array('default' => 'none'),
'options' => array('default' => array()),
),
),
'query' => array(
......@@ -536,12 +530,6 @@ protected function defineOptions() {
'options' => array('default' => array()),
),
),
// Note that exposed_form plugin has options in a separate array,
// while access and cache do not. access and cache are legacy and
// that pattern should not be repeated, but it is left as is to
// reduce the need to modify older views. Let's consider the
// pattern used here to be the template from which future plugins
// should be copied.
'exposed_form' => array(
'contains' => array(
'type' => array('default' => 'basic'),
......@@ -554,21 +542,17 @@ protected function defineOptions() {
'options' => array('default' => array()),
),
),
// Note that the styles have their options completely independent.
// Like access and cache above, this is a legacy pattern and
// should not be repeated.
'style_plugin' => array(
'default' => 'default',
'style' => array(
'contains' => array(
'type' => array('default' => 'default'),
'options' => array('default' => array()),
),
'style_options' => array(
'default' => array(),
),
'row_plugin' => array(
'default' => 'fields',
'row' => array(
'contains' => array(
'type' => array('default' => 'fields'),
'options' => array('default' => array()),
),
'row_options' => array(
'default' => array(),
),
'exposed_block' => array(
......@@ -738,8 +722,8 @@ public function getOption($option) {
* @return bool
*/
public function usesFields() {
$name = $this->getOption('style_plugin');
$plugin = $this->getPlugin('style', $name);
$style = $this->getOption('style');
$plugin = $this->getPlugin('style', $style['type']);
if ($plugin) {
return $plugin->usesFields();
}
......@@ -759,15 +743,6 @@ public function getPlugin($type = 'style', $name = NULL) {
static $cache = array();
if (!isset($cache[$type][$name])) {
switch ($type) {
case 'style':
case 'row':
$option_name = $type . '_plugin';
$options = $this->getOption($type . '_options');
if (!$name) {
$name = $this->getOption($option_name);
}
break;
case 'query':
$views_data = views_fetch_data($this->view->storage->base_table);
$name = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query';
......@@ -778,16 +753,8 @@ public function getPlugin($type = 'style', $name = NULL) {
$name = $options['type'];
}
// access & cache store their options as siblings with the
// type; all others use an 'options' array.
if ($type != 'access' && $type != 'cache') {
if (!isset($options['options'])) {
// debug($type);
// debug($options);
}
$options = $options['options'];
}
}
if ($type != 'query') {
$plugin = views_get_plugin($type, $name);
......@@ -1089,15 +1056,16 @@ public function optionsSummary(&$categories, &$options) {
'desc' => t('Change the title that this display will use.'),
);
$name = $this->getOption('style_plugin');
$style_options = $this->getOption('style');
$name = $style_options['type'];
$style_plugin = views_get_plugin_definition('style', $name);
$style_plugin_instance = $this->getPlugin('style', $name);
$style_plugin_instance = $this->getPlugin('style');
$style_summary = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin_instance->summaryTitle();
$style_title = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin_instance->pluginTitle();
$style = '';
$options['style_plugin'] = array(
$options['style'] = array(
'category' => 'format',
'title' => t('Format'),
'value' => $style_title,
......@@ -1107,17 +1075,18 @@ public function optionsSummary(&$categories, &$options) {
// This adds a 'Settings' link to the style_options setting if the style has options.
if ($style_plugin_instance->usesOptions()) {
$options['style_plugin']['links']['style_options'] = t('Change settings for this format');
$options['style']['links']['style_options'] = t('Change settings for this format');
}
if ($style_plugin_instance->usesRowPlugin()) {
$name = $this->getOption('row_plugin');
$row_options = $this->getOption('row');
$name = $row_options['type'];
$row_plugin = views_get_plugin_definition('row', $name);
$row_plugin_instance = $this->getPlugin('row', $name);
$row_summary = empty($row_plugin['title']) ? t('Missing style plugin') : $row_plugin_instance->summaryTitle();
$row_title = empty($row_plugin['title']) ? t('Missing style plugin') : $row_plugin_instance->pluginTitle();
$options['row_plugin'] = array(
$options['row'] = array(
'category' => 'format',
'title' => t('Show'),
'value' => $row_title,
......@@ -1126,7 +1095,7 @@ public function optionsSummary(&$categories, &$options) {
);
// This adds a 'Settings' link to the row_options setting if the row style has options.
if ($row_plugin_instance->usesOptions()) {
$options['row_plugin']['links']['row_options'] = t('Change settings for this style');
$options['row']['links']['row_options'] = t('Change settings for this style');
}
}
if ($this->usesAJAX()) {
......@@ -1493,17 +1462,12 @@ public function buildOptionsForm(&$form, &$form_state) {
break;
case 'access_options':
$access = $this->getOption('access');
$plugin = $this->getPlugin('access');
$form['#title'] .= t('Access options');
if ($plugin) {
$form['access_options'] = array(
'#tree' => TRUE,
);
$form['access_options']['type'] = array(
'#type' => 'value',