Commit 386bfa9f authored by catch's avatar catch

Issue #1770772 by damiankloip, dawehner, tim.plunkett: Move row_plugin() from...

Issue #1770772 by damiankloip, dawehner, tim.plunkett: Move row_plugin() from style_plugin() to the main view object.
parent 2733a1b1
......@@ -91,7 +91,7 @@ public function render() {
foreach ($sets as $records) {
foreach ($records as $values) {
// Sanitize HTML, remove line breaks and extra whitespace.
$output = $this->row_plugin->render($values);
$output = $this->view->rowPlugin->render($values);
$output = drupal_render($output);
$results[$values->{$id_field_alias}] = filter_xss_admin(preg_replace('/\s\s+/', ' ', str_replace("\n", '', $output)));
$this->view->row_index++;
......
......@@ -650,7 +650,7 @@ function node_views_data() {
*/
function node_row_node_view_preprocess_node(&$vars) {
$node = $vars['node'];
$options = $vars['view']->style_plugin->row_plugin->options;
$options = $vars['view']->rowPlugin->options;
// Prevent the comment form from showing up if this is not a page display.
if ($vars['view_mode'] == 'full' && !$vars['view']->display_handler->hasPath()) {
......
......@@ -66,7 +66,7 @@ public function render() {
// is used, $rows will not contain objects and will pass directly to the
// Encoder.
foreach ($this->view->result as $row) {
$rows[] = $this->row_plugin->render($row);
$rows[] = $this->view->rowPlugin->render($row);
}
return $this->serializer->serialize($rows, $this->displayHandler->getContentType());
......
......@@ -255,16 +255,15 @@ public function attachTo(ViewExecutable $clone, $display_id) {
// Defer to the feed style; it may put in meta information, and/or
// attach a feed icon.
$plugin = $this->getPlugin('style');
if ($plugin) {
$clone->setDisplay($this->display['id']);
$clone->buildTitle();
$clone->setDisplay($this->display['id']);
$clone->buildTitle();
if ($plugin = $clone->display_handler->getPlugin('style')) {
$plugin->attach_to($display_id, $this->getPath(), $clone->getTitle());
// Clean up.
$clone->destroy();
unset($clone);
}
// Clean up.
$clone->destroy();
unset($clone);
}
/**
......
......@@ -108,7 +108,7 @@ function get_description() {
}
function render() {
if (empty($this->row_plugin)) {
if (empty($this->view->rowPlugin)) {
debug('Drupal\views\Plugin\views\style\Rss: Missing row plugin');
return;
}
......@@ -129,7 +129,7 @@ function render() {
foreach ($this->view->result as $row_index => $row) {
$this->view->row_index = $row_index;
$rows .= $this->row_plugin->render($row);
$rows .= $this->view->rowPlugin->render($row);
}
$output = theme($this->themeFunctions(),
......
......@@ -41,14 +41,6 @@ abstract class StylePluginBase extends PluginBase {
*/
var $row_tokens = array();
/**
* Contains the row plugin, if it's initialized
* and the style itself supports it.
*
* @var views_plugin_row
*/
var $row_plugin;
/**
* Does the style plugin allows to use style plugins.
*
......@@ -100,7 +92,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
parent::init($view, $display, $options);
if ($this->usesRowPlugin() && $display->getOption('row')) {
$this->row_plugin = $display->getPlugin('row');
$this->view->rowPlugin = $display->getPlugin('row');
}
$this->options += array(
......@@ -112,8 +104,8 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
public function destroy() {
parent::destroy();
if (isset($this->row_plugin)) {
$this->row_plugin->destroy();
if (isset($this->view->rowPlugin)) {
$this->view->rowPlugin->destroy();
}
}
......@@ -154,8 +146,8 @@ function usesFields() {
// If we use a row plugin, ask the row plugin. Chances are, we don't
// care, it does.
$row_uses_fields = FALSE;
if ($this->usesRowPlugin() && !empty($this->row_plugin)) {
$row_uses_fields = $this->row_plugin->usesFields();
if ($this->usesRowPlugin() && !empty($this->view->rowPlugin)) {
$row_uses_fields = $this->view->rowPlugin->usesFields();
}
// Otherwise, check the definition or the option.
return $row_uses_fields || $this->usesFields || !empty($this->options['uses_fields']);
......@@ -396,8 +388,8 @@ function build_sort_post() { }
* The full array of results from the query.
*/
function pre_render($result) {
if (!empty($this->row_plugin)) {
$this->row_plugin->pre_render($result);
if (!empty($this->view->rowPlugin)) {
$this->view->rowPlugin->pre_render($result);
}
}
......@@ -405,7 +397,7 @@ function pre_render($result) {
* Render the display in this style.
*/
function render() {
if ($this->usesRowPlugin() && empty($this->row_plugin)) {
if ($this->usesRowPlugin() && empty($this->view->rowPlugin)) {
debug('Drupal\views\Plugin\views\style\StylePluginBase: Missing row plugin');
return;
}
......@@ -455,7 +447,7 @@ function render_grouping_sets($sets, $level = 0) {
if ($this->usesRowPlugin()) {
foreach ($set['rows'] as $index => $row) {
$this->view->row_index = $index;
$render = $this->row_plugin->render($row);
$render = $this->view->rowPlugin->render($row);
// Row render arrays cannot be contained by style render arrays.
$set['rows'][$index] = drupal_render($render);
}
......@@ -684,8 +676,8 @@ public function validate() {
public function query() {
parent::query();
if (isset($this->row_plugin)) {
$this->row_plugin->query();
if (isset($this->view->rowPlugin)) {
$this->view->rowPlugin->query();
}
}
......
......@@ -80,10 +80,10 @@ public function testStyle() {
$view->style_plugin->setUsesRowPlugin(TRUE);
// Reinitialize the style as it supports row plugins now.
$view->style_plugin->init($view, $view->display_handler);
$this->assertTrue($view->style_plugin->row_plugin instanceof RowTest, 'Make sure the right row plugin class is loaded.');
$this->assertTrue($view->rowPlugin instanceof RowTest, 'Make sure the right row plugin class is loaded.');
$random_text = $this->randomName();
$view->style_plugin->row_plugin->setOutput($random_text);
$view->rowPlugin->setOutput($random_text);
$output = $view->preview();
$this->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the row plugin appears in the output of the view.');
......
......@@ -14,6 +14,8 @@
use Drupal\views\Plugin\views\display\DefaultDisplay;
use Drupal\views\Plugin\views\display\Page;
use Drupal\views\Plugin\views\style\DefaultStyle;
use Drupal\views\Plugin\views\style\Grid;
use Drupal\views\Plugin\views\row\Fields;
use Drupal\views\Plugin\views\query\Sql;
/**
......@@ -192,6 +194,21 @@ public function testDisplays() {
$view->setDisplay('invalid');
$this->assertEqual($view->current_display, 'default', 'If setDisplay is called with an invalid display id the default display should be used.');
$this->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers->get('default')));
// Test the style and row plugins are replaced correctly when setting the
// display.
$view->setDisplay('page_1');
$view->initStyle();
$this->assertTrue($view->style_plugin instanceof DefaultStyle);
$this->assertTrue($view->rowPlugin instanceof Fields);
$this->assertEqual($view->plugin_name, 'default');
$view->setDisplay('page_2');
$view->initStyle();
$this->assertTrue($view->style_plugin instanceof Grid);
// @todo Change this rowPlugin type too.
$this->assertTrue($view->rowPlugin instanceof Fields);
$this->assertEqual($view->plugin_name, 'grid');
}
/**
......
......@@ -211,6 +211,13 @@ class ViewExecutable {
*/
public $style_plugin;
/**
* The current used row plugin, if the style plugin supports row plugins.
*
* @var \Drupal\views\Plugin\views\row\RowPluginBase
*/
public $rowPlugin;
/**
* Stores the current active row while rendering.
*
......@@ -671,8 +678,17 @@ public function setDisplay($display_id = NULL) {
}
}
// Set the current display.
$this->current_display = $display_id;
// Reset if the display has changed. It could be called multiple times for
// the same display, especially in the UI.
if ($this->current_display != $display_id) {
// Set the current display.
$this->current_display = $display_id;
// Reset the style and row plugins.
$this->style_plugin = NULL;
$this->plugin_name = NULL;
$this->rowPlugin = NULL;
}
// Ensure requested display has a working handler.
if (!$this->displayHandlers->has($display_id)) {
......@@ -1737,7 +1753,7 @@ public function destroy() {
$this->style_plugin->destroy();
}
$keys = array('current_display', 'display_handler', 'displayHandlers', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'result', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'many_to_one_tables');
$keys = array('current_display', 'display_handler', 'displayHandlers', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'result', 'inited', 'style_plugin', 'rowPlugin', 'plugin_name', 'exposed_data', 'exposed_input', 'many_to_one_tables');
foreach ($keys as $key) {
unset($this->$key);
}
......
......@@ -18,6 +18,11 @@ display:
display_title: 'Page 2'
id: page_2
position: '2'
display_options:
defaults:
style: '0'
style:
type: grid
human_name: ''
id: test_executable_displays
tag: ''
......@@ -100,7 +100,7 @@ public function render() {
else {
foreach ($this->view->result as $index => $row) {
$this->view->row_index = $index;
$output .= $this->row_plugin->render($row) . "\n";
$output .= $this->view->rowPlugin->render($row) . "\n";
}
}
......
......@@ -864,10 +864,15 @@ public function buildOptionForm(ViewUI $view, $id, $option, $display) {
* Add information about a section to a display.
*/
public function getFormBucket(ViewUI $view, $type, $display) {
$executable = $view->get('executable');
$executable->setDisplay($display['id']);
$executable->initStyle();
$types = $executable->viewsHandlerTypes();
$build = array(
'#theme_wrappers' => array('views_ui_display_tab_bucket'),
);
$types = ViewExecutable::viewsHandlerTypes();
$build['#overridden'] = FALSE;
$build['#defaulted'] = FALSE;
......@@ -891,7 +896,7 @@ public function getFormBucket(ViewUI $view, $type, $display) {
break;
case 'field':
// Fetch the style plugin info so we know whether to list fields or not.
$style_plugin = $view->get('executable')->displayHandlers->get($display['id'])->getPlugin('style');
$style_plugin = $executable->style_plugin;
$uses_fields = $style_plugin && $style_plugin->usesFields();
if (!$uses_fields) {
$build['fields'][] = array(
......@@ -905,7 +910,7 @@ public function getFormBucket(ViewUI $view, $type, $display) {
case 'header':
case 'footer':
case 'empty':
if (!$view->get('executable')->displayHandlers->get($display['id'])->usesAreas()) {
if (!$executable->display_handler->usesAreas()) {
$build[$type][] = array(
'#markup' => t('The selected display type does not utilize @type plugins', array('@type' => $type)),
'#theme_wrappers' => array('views_ui_container'),
......@@ -918,7 +923,7 @@ public function getFormBucket(ViewUI $view, $type, $display) {
// Create an array of actions to pass to theme_links
$actions = array();
$count_handlers = count($view->get('executable')->displayHandlers->get($display['id'])->getHandlers($type));
$count_handlers = count($executable->display_handler->getHandlers($type));
$actions['add'] = array(
'title' => t('Add'),
'href' => "admin/structure/views/nojs/add-item/{$view->id()}/{$display['id']}/$type",
......@@ -943,8 +948,8 @@ public function getFormBucket(ViewUI $view, $type, $display) {
),
);
if (!$view->get('executable')->displayHandlers->get($display['id'])->isDefaultDisplay()) {
if (!$view->get('executable')->displayHandlers->get($display['id'])->isDefaulted($types[$type]['plural'])) {
if (!$executable->display_handler->isDefaultDisplay()) {
if (!$executable->display_handler->isDefaulted($types[$type]['plural'])) {
$build['#overridden'] = TRUE;
}
else {
......@@ -956,7 +961,7 @@ public function getFormBucket(ViewUI $view, $type, $display) {
if (!isset($relationships)) {
// Get relationship labels
$relationships = array();
foreach ($view->get('executable')->displayHandlers->get($display['id'])->getHandlers('relationship') as $id => $handler) {
foreach ($executable->display_handler->getHandlers('relationship') as $id => $handler) {
$relationships[$id] = $handler->label();
}
}
......@@ -965,7 +970,7 @@ public function getFormBucket(ViewUI $view, $type, $display) {
$groups = array();
$grouping = FALSE;
if ($type == 'filter') {
$group_info = $view->get('executable')->displayHandlers->get('default')->getOption('filter_groups');
$group_info = $executable->display_handler->getOption('filter_groups');
// If there is only one group but it is using the "OR" filter, we still
// treat it as a group for display purposes, since we want to display the
// "OR" label next to items within the group.
......@@ -977,12 +982,12 @@ public function getFormBucket(ViewUI $view, $type, $display) {
$build['fields'] = array();
foreach ($view->get('executable')->displayHandlers->get($display['id'])->getOption($types[$type]['plural']) as $id => $field) {
foreach ($executable->display_handler->getOption($types[$type]['plural']) as $id => $field) {
// Build the option link for this handler ("Node: ID = article").
$build['fields'][$id] = array();
$build['fields'][$id]['#theme'] = 'views_ui_display_tab_setting';
$handler = $view->get('executable')->displayHandlers->get($display['id'])->getHandler($type, $id);
$handler = $executable->display_handler->getHandler($type, $id);
if (empty($handler)) {
$build['fields'][$id]['#class'][] = 'broken';
$field_name = t('Broken/missing handler: @table > @field', array('@table' => $field['table'], '@field' => $field['field']));
......@@ -1004,7 +1009,7 @@ public function getFormBucket(ViewUI $view, $type, $display) {
$build['fields'][$id]['#link'] = l($link_text, "admin/structure/views/nojs/config-item/{$view->id()}/{$display['id']}/$type/$id", array('attributes' => $link_attributes, 'html' => TRUE));
$build['fields'][$id]['#class'][] = drupal_clean_css_identifier($display['id']. '-' . $type . '-' . $id);
if ($view->get('executable')->displayHandlers->get($display['id'])->useGroupBy() && $handler->usesGroupBy()) {
if ($executable->display_handler->useGroupBy() && $handler->usesGroupBy()) {
$build['fields'][$id]['#settings_links'][] = l('<span class="label">' . t('Aggregation settings') . '</span>', "admin/structure/views/nojs/config-item-group/{$view->id()}/{$display['id']}/$type/$id", array('attributes' => array('class' => 'views-button-configure views-ajax-link', 'title' => t('Aggregation settings')), 'html' => TRUE));
}
......
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