Commit ccc66002 authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1788238 by dawehner: Cleanup display and seperate options from instances.

parent 277f8195
This diff is collapsed.
......@@ -69,7 +69,7 @@ function views_ajax() {
// Override the display's pager_element with the one actually used.
if (isset($pager_element)) {
$commands[] = views_ajax_command_scroll_top('.view-dom-id-' . $dom_id);
$view->display[$display_id]->handler->setOption('pager_element', $pager_element);
$view->displayHandlers[$display_id]->setOption('pager_element', $pager_element);
}
// Reuse the same DOM id so it matches that in Drupal.settings.
$view->dom_id = $dom_id;
......
......@@ -23,14 +23,14 @@ function views_ui_views_analyze($view) {
// You can give a page display the same path as an alias existing in the
// system, so the alias will not work anymore. Report this to the user,
// because he probably wanted something else.
foreach ($view->display as $id => $display) {
if (empty($display->handler)) {
foreach ($view->displayHandlers as $display) {
if (empty($display)) {
continue;
}
if ($display->handler->hasPath() && $path = $display->handler->getOption('path')) {
if ($display->hasPath() && $path = $display->getOption('path')) {
$normal_path = drupal_get_normal_path($path);
if ($path != $normal_path) {
$ret[] = Analyzer::formatMessage(t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', array('%display' => $display->display_title)), 'warning');
$ret[] = Analyzer::formatMessage(t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', array('%display' => $display['display_title'])), 'warning');
}
}
}
......
......@@ -326,7 +326,7 @@ public function buildGroupByForm(&$form, &$form_state) {
$type = $form_state['type'];
$id = $form_state['id'];
$form['#title'] = check_plain($view->display[$display_id]->display_title) . ': ';
$form['#title'] = check_plain($view->display[$display_id]['display_title']) . ': ';
$form['#title'] .= t('Configure aggregation settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $this->adminLabel()));
$form['#section'] = $display_id . '-' . $type . '-' . $id;
......
......@@ -26,6 +26,17 @@ abstract class PluginBase extends ComponentPluginBase {
*/
public $view = NULL;
/**
* The display object this plugin is for.
*
* For display plugins this is empty.
*
* @todo find a better description
*
* @var Drupal\views\Plugin\views\display\DisplayPluginBase
*/
public $displayHandler;
/**
* Plugins's definition
*
......@@ -40,6 +51,7 @@ abstract class PluginBase extends ComponentPluginBase {
*/
protected $usesOptions = FALSE;
/**
* Constructs a Plugin object.
*/
......@@ -164,7 +176,7 @@ public function query() { }
* Provide a full list of possible theme templates used by this style.
*/
public function themeFunctions() {
return views_theme_functions($this->definition['theme'], $this->view, $this->display);
return views_theme_functions($this->definition['theme'], $this->view, $this->view->display_handler->display);
}
/**
......@@ -174,7 +186,7 @@ public function additionalThemeFunctions() {
$funcs = array();
if (!empty($this->definition['additional themes'])) {
foreach ($this->definition['additional themes'] as $theme => $type) {
$funcs[] = views_theme_functions($theme, $this->view, $this->display);
$funcs[] = views_theme_functions($theme, $this->view, $this->view->display_handler->display);
}
}
return $funcs;
......
......@@ -36,10 +36,10 @@ abstract class AccessPluginBase extends PluginBase {
public function init(&$view, &$display) {
$this->setOptionDefaults($this->options, $this->defineOptions());
$this->view = &$view;
$this->display = &$display;
$this->displayHandler = &$display;
if (is_object($display->handler)) {
$options = $display->handler->getOption('access');
if (is_object($display)) {
$options = $display->getOption('access');
// Overlay incoming options on top of defaults
$this->unpackOptions($this->options, $options);
}
......
......@@ -65,10 +65,10 @@ abstract class CachePluginBase extends PluginBase {
public function init(&$view, &$display) {
$this->setOptionDefaults($this->options, $this->defineOptions());
$this->view = &$view;
$this->display = &$display;
$this->displayHandler = &$display;
if (is_object($display->handler)) {
$options = $display->handler->getOption('cache');
if (is_object($display)) {
$options = $display->getOption('cache');
// Overlay incoming options on top of defaults
$this->unpackOptions($this->options, $options);
}
......@@ -302,7 +302,7 @@ function get_results_key() {
}
}
$this->_results_key = $this->view->name . ':' . $this->display->id . ':results:' . md5(serialize($key_data));
$this->_results_key = $this->view->name . ':' . $this->displayHandler->display['id'] . ':results:' . md5(serialize($key_data));
}
return $this->_results_key;
......@@ -320,7 +320,7 @@ function get_output_key() {
'base_url' => $GLOBALS['base_url'],
);
$this->_output_key = $this->view->name . ':' . $this->display->id . ':output:' . md5(serialize($key_data));
$this->_output_key = $this->view->name . ':' . $this->displayHandler->display['id'] . ':output:' . md5(serialize($key_data));
}
return $this->_output_key;
......
......@@ -50,7 +50,7 @@ protected function defineOptions() {
}
public function execute() {
return $this->view->render($this->display->id);
return $this->view->render($this->display['id']);
}
public function attachmentPositions($position = NULL) {
......@@ -91,7 +91,7 @@ public function optionsSummary(&$categories, &$options) {
elseif (count($displays) == 1) {
$display = array_shift($displays);
if (!empty($this->view->display[$display])) {
$attach_to = check_plain($this->view->display[$display]->display_title);
$attach_to = check_plain($this->view->display[$display]['display_title']);
}
}
......@@ -194,8 +194,8 @@ public function buildOptionsForm(&$form, &$form_state) {
$form['#title'] .= t('Attach to');
$displays = array();
foreach ($this->view->display as $display_id => $display) {
if (!empty($display->handler) && $display->handler->acceptAttachments()) {
$displays[$display_id] = $display->display_title;
if (!empty($this->view->displayHandlers[$display_id]) && $this->view->displayHandlers[$display_id]->acceptAttachments()) {
$displays[$display_id] = $display['display_title'];
}
}
$form['displays'] = array(
......@@ -247,13 +247,13 @@ public function attachTo($display_id) {
$args = $this->getOption('inherit_arguments') ? $this->view->args : array();
$view->setArguments($args);
$view->setDisplay($this->display->id);
$view->setDisplay($this->display['id']);
if ($this->getOption('inherit_pager')) {
$view->display_handler->usesPager = $this->view->display[$display_id]->handler->usesPager();
$view->display_handler->setOption('pager', $this->view->display[$display_id]->handler->getOption('pager'));
}
$attachment = $view->executeDisplay($this->display->id, $args);
$attachment = $view->executeDisplay($this->display['id'], $args);
switch ($this->getOption('attachment_position')) {
case 'before':
......
......@@ -73,7 +73,7 @@ public function isDefaultDisplay() { return TRUE; }
* data if necessary.
*/
public function execute() {
return $this->view->render($this->display->id);
return $this->view->render($this->display['id']);
}
}
......@@ -107,8 +107,8 @@ public function init(&$view, &$display, $options = NULL) {
$changed = FALSE;
// Make some modifications:
if (!isset($options) && isset($display->display_options)) {
$options = $display->display_options;
if (!isset($options) && isset($display['display_options'])) {
$options = $display['display_options'];
}
if ($this->isDefaultDisplay() && isset($options['defaults'])) {
......@@ -666,9 +666,9 @@ public function usesExposedFormInBlock() { return $this->hasPath(); }
public function getLinkDisplay() {
$display_id = $this->getOption('link_display');
// If unknown, pick the first one.
if (empty($display_id) || empty($this->view->display[$display_id])) {
foreach ($this->view->display as $display_id => $display) {
if (!empty($display->handler) && $display->handler->hasPath()) {
if (empty($display_id) || empty($this->view->displayHandlers[$display_id])) {
foreach ($this->view->displayHandlers as $display_id => $display) {
if (!empty($display) && $display->hasPath()) {
return $display_id;
}
}
......@@ -691,8 +691,8 @@ public function getPath() {
}
$display_id = $this->getLinkDisplay();
if ($display_id && !empty($this->view->display[$display_id]) && is_object($this->view->display[$display_id]->handler)) {
return $this->view->display[$display_id]->handler->getPath();
if ($display_id && !empty($this->view->displayHandlers[$display_id]) && is_object($this->view->displayHandlers[$display_id])) {
return $this->view->displayHandlers[$display_id]->getPath();
}
}
......@@ -800,10 +800,10 @@ public function getPlugin($type = 'style', $name = NULL) {
return;
}
if ($type != 'query') {
$plugin->init($this->view, $this->display, $options);
$plugin->init($this->view, $this, $options);
}
else {
$display_id = $this->isDefaulted($option_name) ? $this->display->id : 'default';
$display_id = $this->isDefaulted($option_name) ? $this->display['id'] : 'default';
if (!isset($this->base_field)) {
$views_data = views_fetch_data($this->view->base_table);
......@@ -950,7 +950,7 @@ public function setOption($option, $value) {
// Set this in two places: On the handler where we'll notice it
// but also on the display object so it gets saved. This should
// only be a temporary fix.
$this->display->display_options[$option] = $value;
$this->display['display_options'][$option] = $value;
return $this->options[$option] = $value;
}
......@@ -980,7 +980,7 @@ public function optionLink($text, $section, $class = '', $title = '') {
$title = $text;
}
return l($text, 'admin/structure/views/nojs/display/' . $this->view->name . '/' . $this->display->id . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title, 'id' => drupal_html_id('views-' . $this->display->id . '-' . $section)), 'html' => TRUE));
return l($text, 'admin/structure/views/nojs/display/' . $this->view->name . '/' . $this->display['id'] . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE));
}
/**
......@@ -1060,11 +1060,11 @@ public function optionsSummary(&$categories, &$options) {
),
);
if ($this->display->id != 'default') {
if ($this->display['id'] != 'default') {
$options['display_id'] = array(
'category' => 'other',
'title' => t('Machine Name'),
'value' => !empty($this->display->new_id) ? check_plain($this->display->new_id) : check_plain($this->display->id),
'value' => !empty($this->display['new_id']) ? check_plain($this->display['new_id']) : check_plain($this->display['id']),
'desc' => t('Change the machine name of this display.'),
);
}
......@@ -1266,7 +1266,7 @@ public function optionsSummary(&$categories, &$options) {
if ($this->usesLinkDisplay()) {
$display_id = $this->getLinkDisplay();
$link_display = empty($this->view->display[$display_id]) ? t('None') : check_plain($this->view->display[$display_id]->display_title);
$link_display = empty($this->view->display[$display_id]) ? t('None') : check_plain($this->view->display[$display_id]['display_title']);
$link_display = $this->getOption('link_display') == 'custom_url' ? t('Custom URL') : $link_display;
$options['link_display'] = array(
'category' => 'other',
......@@ -1337,7 +1337,7 @@ public function buildOptionsForm(&$form, &$form_state) {
if ($this->defaultableSections($form_state['section'])) {
views_ui_standard_display_dropdown($form, $form_state, $form_state['section']);
}
$form['#title'] = check_plain($this->display->display_title) . ': ';
$form['#title'] = check_plain($this->display['display_title']) . ': ';
// Set the 'section' to hilite on the form.
// If it's the item we're looking at is pulling from the default display,
......@@ -1347,7 +1347,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$form['#section'] = 'default-' . $form_state['section'];
}
else {
$form['#section'] = $this->display->id . '-' . $form_state['section'];
$form['#section'] = $this->display['id'] . '-' . $form_state['section'];
}
switch ($form_state['section']) {
......@@ -1356,7 +1356,7 @@ public function buildOptionsForm(&$form, &$form_state) {
$form['display_id'] = array(
'#type' => 'textfield',
'#description' => t('This is machine name of the display.'),
'#default_value' => !empty($this->display->new_id) ? $this->display->new_id : $this->display->id,
'#default_value' => !empty($this->display['new_id']) ? $this->display['new_id'] : $this->display['id'],
'#required' => TRUE,
'#size' => 64,
);
......@@ -1367,7 +1367,7 @@ public function buildOptionsForm(&$form, &$form_state) {
'#title' => t('Name'),
'#type' => 'textfield',
'#description' => t('This name will appear only in the administrative interface for the View.'),
'#default_value' => $this->display->display_title,
'#default_value' => $this->display['display_title'],
);
$form['display_description'] = array(
'#title' => t('Description'),
......@@ -1670,8 +1670,8 @@ public function buildOptionsForm(&$form, &$form_state) {
case 'link_display':
$form['#title'] .= t('Which display to use for path');
foreach ($this->view->display as $display_id => $display) {
if ($display->handler->hasPath()) {
$options[$display_id] = $display->display_title;
if ($this->view->displayHandlers[$display_id]->hasPath()) {
$options[$display_id] = $display['display_title'];
}
}
$options['custom_url'] = t('Custom URL');
......@@ -2128,7 +2128,7 @@ public function validateOptionsForm(&$form, &$form_state) {
}
foreach ($this->view->display as $id => $display) {
if ($id != $this->view->current_display && ($form_state['values']['display_id'] == $id || (isset($display->new_id) && $form_state['values']['display_id'] == $display->new_id))) {
if ($id != $this->view->current_display && ($form_state['values']['display_id'] == $id || (isset($display['new_id']) && $form_state['values']['display_id'] == $display['new_id']))) {
form_error($form['display_id'], t('Display id should be unique.'));
}
}
......@@ -2194,11 +2194,11 @@ public function submitOptionsForm(&$form, &$form_state) {
switch ($section) {
case 'display_id':
if (isset($form_state['values']['display_id'])) {
$this->display->new_id = $form_state['values']['display_id'];
$this->display['new_id'] = $form_state['values']['display_id'];
}
break;
case 'display_title':
$this->display->display_title = $form_state['values']['display_title'];
$this->display['display_title'] = $form_state['values']['display_title'];
$this->setOption('display_description', $form_state['values']['display_description']);
break;
case 'access':
......@@ -2209,7 +2209,7 @@ public function submitOptionsForm(&$form, &$form_state) {
$access = array('type' => $form_state['values']['access']['type']);
$this->setOption('access', $access);
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('access_options'));
views_ui_add_form_to_stack('display', $this->view, $this->display['id'], array('access_options'));
}
}
}
......@@ -2230,7 +2230,7 @@ public function submitOptionsForm(&$form, &$form_state) {
$cache = array('type' => $form_state['values']['cache']['type']);
$this->setOption('cache', $cache);
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('cache_options'));
views_ui_add_form_to_stack('display', $this->view, $this->display['id'], array('cache_options'));
}
}
}
......@@ -2288,7 +2288,7 @@ public function submitOptionsForm(&$form, &$form_state) {
// send ajax form to options page if we use it.
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('row_options'));
views_ui_add_form_to_stack('display', $this->view, $this->display['id'], array('row_options'));
}
}
}
......@@ -2303,7 +2303,7 @@ public function submitOptionsForm(&$form, &$form_state) {
$this->setOption('style_options', array());
// send ajax form to options page if we use it.
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('style_options'));
views_ui_add_form_to_stack('display', $this->view, $this->display['id'], array('style_options'));
}
}
}
......@@ -2329,7 +2329,7 @@ public function submitOptionsForm(&$form, &$form_state) {
$exposed_form = array('type' => $form_state['values']['exposed_form']['type'], 'options' => array());
$this->setOption('exposed_form', $exposed_form);
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('exposed_form_options'));
views_ui_add_form_to_stack('display', $this->view, $this->display['id'], array('exposed_form_options'));
}
}
}
......@@ -2356,7 +2356,7 @@ public function submitOptionsForm(&$form, &$form_state) {
$pager = array('type' => $form_state['values']['pager']['type'], 'options' => $plugin->options);
$this->setOption('pager', $pager);
if ($plugin->usesOptions()) {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('pager_options'));
views_ui_add_form_to_stack('display', $this->view, $this->display['id'], array('pager_options'));
}
}
}
......@@ -2410,15 +2410,15 @@ public function setOverride($section, $new_state = NULL) {
if ($new_state) {
// Revert to defaults.
unset($this->options[$option]);
unset($this->display->display_options[$option]);
unset($this->display['display_options'][$option]);
}
else {
// copy existing values into our display.
$this->options[$option] = $this->getOption($option);
$this->display->display_options[$option] = $this->options[$option];
$this->display['display_options'][$option] = $this->options[$option];
}
$this->options['defaults'][$option] = $new_state;
$this->display->display_options['defaults'][$option] = $new_state;
$this->display['display_options']['defaults'][$option] = $new_state;
}
}
......@@ -2465,7 +2465,7 @@ public function renderMoreLink() {
if (!empty($this->view->exposed_raw_input)) {
$url_options['query'] = $this->view->exposed_raw_input;
}
$theme = views_theme_functions('views_more', $this->view, $this->display);
$theme = views_theme_functions('views_more', $this->view, $this->view->display[$this->view->current_display]);
$path = check_url(url($path, $url_options));
return theme($theme, array('more_url' => $path, 'link_text' => check_plain($this->useMoreText()), 'view' => $this->view));
......@@ -2610,19 +2610,19 @@ public function validate() {
}
if (!$fields) {
$errors[] = t('Display "@display" uses fields but there are none defined for it or all are excluded.', array('@display' => $this->display->display_title));
$errors[] = t('Display "@display" uses fields but there are none defined for it or all are excluded.', array('@display' => $this->display['display_title']));
}
}
if ($this->hasPath() && !$this->getOption('path')) {
$errors[] = t('Display "@display" uses a path but the path is undefined.', array('@display' => $this->display->display_title));
$errors[] = t('Display "@display" uses a path but the path is undefined.', array('@display' => $this->display['display_title']));
}
// Validate style plugin
$name = $this->getOption('style_plugin');
$style = $this->getPlugin('style', $name);
if (empty($style)) {
$errors[] = t('Display "@display" has an invalid style plugin.', array('@display' => $this->display->display_title));
$errors[] = t('Display "@display" has an invalid style plugin.', array('@display' => $this->display['display_title']));
}
else {
$result = $style->validate();
......@@ -2690,8 +2690,8 @@ public function getSpecialBlocks() {
$blocks = array();
if ($this->usesExposedFormInBlock()) {
$delta = '-exp-' . $this->view->name . '-' . $this->display->id;
$desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->name, '@display_id' => $this->display->id));
$delta = '-exp-' . $this->view->name . '-' . $this->display['id'];
$desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->name, '@display_id' => $this->display['id']));
$blocks[$delta] = array(
'info' => $desc,
......
......@@ -153,7 +153,7 @@ public function optionsSummary(&$categories, &$options) {
elseif (count($displays) == 1) {
$display = array_shift($displays);
if (!empty($this->view->display[$display])) {
$attach_to = check_plain($this->view->display[$display]->display_title);
$attach_to = check_plain($this->view->display[$display]['display_title']);
}
}
......@@ -196,8 +196,9 @@ public function buildOptionsForm(&$form, &$form_state) {
$form['#title'] .= t('Attach to');
$displays = array();
foreach ($this->view->display as $display_id => $display) {
if (!empty($display->handler) && $display->handler->acceptAttachments()) {
$displays[$display_id] = $display->display_title;
// @todo The display plugin should have display_title and id as well.
if (!empty($this->view->displayHandlers[$display_id]) && $this->view->displayHandlers[$display_id]->acceptAttachments()) {
$displays[$display_id] = $display['display_title'];
}
}
$form['displays'] = array(
......@@ -244,7 +245,7 @@ public function attachTo($display_id) {
$plugin = $this->getPlugin('style', $name);
if ($plugin) {
$clone = $this->view->cloneView();
$clone->setDisplay($this->display->id);
$clone->setDisplay($this->display['id']);
$clone->buildTitle();
$plugin->attach_to($display_id, $this->getPath(), $clone->getTitle());
......
......@@ -80,7 +80,7 @@ public function executeHookMenu($callbacks) {
// views_arg_load -- which lives in views.module
$bits = explode('/', $this->getOption('path'));
$page_arguments = array($this->view->name, $this->display->id);
$page_arguments = array($this->view->name, $this->display['id']);
$this->view->initHandlers();
$view_arguments = $this->view->argument;
......@@ -141,7 +141,7 @@ public function executeHookMenu($callbacks) {
'access callback' => 'views_access',
'access arguments' => $access_arguments,
// Identify URL embedded arguments and correlate them to a handler
'load arguments' => array($this->view->name, $this->display->id, '%index'),
'load arguments' => array($this->view->name, $this->display['id'], '%index'),
);
$menu = $this->getOption('menu');
if (empty($menu)) {
......@@ -202,7 +202,7 @@ public function executeHookMenu($callbacks) {
'access callback' => 'views_access',
'access arguments' => $access_arguments,
// Identify URL embedded arguments and correlate them to a handler
'load arguments' => array($this->view->name, $this->display->id, '%index'),
'load arguments' => array($this->view->name, $this->display['id'], '%index'),
'title' => $tab_options['title'],
'description' => $tab_options['description'],
'menu_name' => $tab_options['name'],
......@@ -609,7 +609,7 @@ public function submitOptionsForm(&$form, &$form_state) {
$this->setOption('menu', $form_state['values']['menu']);
// send ajax form to options page if we use it.
if ($form_state['values']['menu']['type'] == 'default tab') {
views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('tab_options'));
views_ui_add_form_to_stack('display', $this->view, $this->display['id'], array('tab_options'));
}
break;
case 'tab_options':
......@@ -623,13 +623,13 @@ public function validate() {
$menu = $this->getOption('menu');
if (!empty($menu['type']) && $menu['type'] != 'none' && empty($menu['title'])) {
$errors[] = t('Display @display is set to use a menu but the menu link text is not set.', array('@display' => $this->display->display_title));
$errors[] = t('Display @display is set to use a menu but the menu link text is not set.', array('@display' => $this->display['display_title']));
}
if ($menu['type'] == 'default tab') {
$tab_options = $this->getOption('tab_options');
if (!empty($tab_options['type']) && $tab_options['type'] != 'none' && empty($tab_options['title'])) {
$errors[] = t('Display @display is set to use a parent menu but the parent menu link text is not set.', array('@display' => $this->display->display_title));
$errors[] = t('Display @display is set to use a parent menu but the parent menu link text is not set.', array('@display' => $this->display['display_title']));
}
}
......
......@@ -40,7 +40,7 @@ abstract class ExposedFormPluginBase extends PluginBase {
public function init(&$view, &$display, $options = array()) {
$this->setOptionDefaults($this->options, $this->defineOptions());
$this->view = &$view;
$this->display = &$display;
$this->displayHandler = &$display;
$this->unpackOptions($this->options, $options);
}
......
......@@ -85,10 +85,10 @@ function pre_render($values) {
);