From 2fcadb11fabd66db851344d2417148d14f447273 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 18 Feb 2013 13:08:32 +0000 Subject: [PATCH] Revert "Issue #1770772 by damiankloip, dawehner, tim.plunkett: Move row_plugin() from style_plugin() to the main view object." This reverts commit 386bfa9fd37980189deed2834130a5b0fd121ee8. --- .../Plugin/views/style/EntityReference.php | 2 +- core/modules/node/node.views.inc | 2 +- .../rest/Plugin/views/style/Serializer.php | 2 +- .../views/Plugin/views/display/Feed.php | 15 +++++----- .../Drupal/views/Plugin/views/style/Rss.php | 4 +-- .../Plugin/views/style/StylePluginBase.php | 30 ++++++++++++------- .../Drupal/views/Tests/Plugin/StyleTest.php | 4 +-- .../Drupal/views/Tests/ViewExecutableTest.php | 17 ----------- .../views/lib/Drupal/views/ViewExecutable.php | 22 ++------------ .../views.view.test_executable_displays.yml | 5 ---- .../Plugin/views/style/StyleTest.php | 2 +- .../views_ui/ViewEditFormController.php | 27 +++++++---------- 12 files changed, 49 insertions(+), 83 deletions(-) diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/style/EntityReference.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/style/EntityReference.php index 3a95929791e..e3f20691675 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/style/EntityReference.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/views/style/EntityReference.php @@ -91,7 +91,7 @@ class EntityReference extends StylePluginBase { foreach ($sets as $records) { foreach ($records as $values) { // Sanitize HTML, remove line breaks and extra whitespace. - $output = $this->view->rowPlugin->render($values); + $output = $this->row_plugin->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++; diff --git a/core/modules/node/node.views.inc b/core/modules/node/node.views.inc index 2f4afeae84d..cd6575ef8bd 100644 --- a/core/modules/node/node.views.inc +++ b/core/modules/node/node.views.inc @@ -650,7 +650,7 @@ function node_views_data() { */ function node_row_node_view_preprocess_node(&$vars) { $node = $vars['node']; - $options = $vars['view']->rowPlugin->options; + $options = $vars['view']->style_plugin->row_plugin->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()) { diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php index 92dfd09ffba..037534fe019 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php @@ -66,7 +66,7 @@ class Serializer extends StylePluginBase { // is used, $rows will not contain objects and will pass directly to the // Encoder. foreach ($this->view->result as $row) { - $rows[] = $this->view->rowPlugin->render($row); + $rows[] = $this->row_plugin->render($row); } return $this->serializer->serialize($rows, $this->displayHandler->getContentType()); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.php index 509e1919e44..1fe792dae7d 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/Feed.php @@ -255,15 +255,16 @@ class Feed extends PathPluginBase { // Defer to the feed style; it may put in meta information, and/or // attach a feed icon. - $clone->setDisplay($this->display['id']); - $clone->buildTitle(); - if ($plugin = $clone->display_handler->getPlugin('style')) { + $plugin = $this->getPlugin('style'); + if ($plugin) { + $clone->setDisplay($this->display['id']); + $clone->buildTitle(); $plugin->attach_to($display_id, $this->getPath(), $clone->getTitle()); - } - // Clean up. - $clone->destroy(); - unset($clone); + // Clean up. + $clone->destroy(); + unset($clone); + } } /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/style/Rss.php b/core/modules/views/lib/Drupal/views/Plugin/views/style/Rss.php index f65004ba360..cdde0578f27 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/Rss.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/Rss.php @@ -108,7 +108,7 @@ class Rss extends StylePluginBase { } function render() { - if (empty($this->view->rowPlugin)) { + if (empty($this->row_plugin)) { debug('Drupal\views\Plugin\views\style\Rss: Missing row plugin'); return; } @@ -129,7 +129,7 @@ class Rss extends StylePluginBase { foreach ($this->view->result as $row_index => $row) { $this->view->row_index = $row_index; - $rows .= $this->view->rowPlugin->render($row); + $rows .= $this->row_plugin->render($row); } $output = theme($this->themeFunctions(), diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php index 15861a67671..1fd2c22297c 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/StylePluginBase.php @@ -41,6 +41,14 @@ 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. * @@ -92,7 +100,7 @@ abstract class StylePluginBase extends PluginBase { parent::init($view, $display, $options); if ($this->usesRowPlugin() && $display->getOption('row')) { - $this->view->rowPlugin = $display->getPlugin('row'); + $this->row_plugin = $display->getPlugin('row'); } $this->options += array( @@ -104,8 +112,8 @@ abstract class StylePluginBase extends PluginBase { public function destroy() { parent::destroy(); - if (isset($this->view->rowPlugin)) { - $this->view->rowPlugin->destroy(); + if (isset($this->row_plugin)) { + $this->row_plugin->destroy(); } } @@ -146,8 +154,8 @@ abstract class StylePluginBase extends PluginBase { // 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->view->rowPlugin)) { - $row_uses_fields = $this->view->rowPlugin->usesFields(); + if ($this->usesRowPlugin() && !empty($this->row_plugin)) { + $row_uses_fields = $this->row_plugin->usesFields(); } // Otherwise, check the definition or the option. return $row_uses_fields || $this->usesFields || !empty($this->options['uses_fields']); @@ -388,8 +396,8 @@ abstract class StylePluginBase extends PluginBase { * The full array of results from the query. */ function pre_render($result) { - if (!empty($this->view->rowPlugin)) { - $this->view->rowPlugin->pre_render($result); + if (!empty($this->row_plugin)) { + $this->row_plugin->pre_render($result); } } @@ -397,7 +405,7 @@ abstract class StylePluginBase extends PluginBase { * Render the display in this style. */ function render() { - if ($this->usesRowPlugin() && empty($this->view->rowPlugin)) { + if ($this->usesRowPlugin() && empty($this->row_plugin)) { debug('Drupal\views\Plugin\views\style\StylePluginBase: Missing row plugin'); return; } @@ -447,7 +455,7 @@ abstract class StylePluginBase extends PluginBase { if ($this->usesRowPlugin()) { foreach ($set['rows'] as $index => $row) { $this->view->row_index = $index; - $render = $this->view->rowPlugin->render($row); + $render = $this->row_plugin->render($row); // Row render arrays cannot be contained by style render arrays. $set['rows'][$index] = drupal_render($render); } @@ -676,8 +684,8 @@ abstract class StylePluginBase extends PluginBase { public function query() { parent::query(); - if (isset($this->view->rowPlugin)) { - $this->view->rowPlugin->query(); + if (isset($this->row_plugin)) { + $this->row_plugin->query(); } } diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php index 2e5f4d2a83d..8a14ca03dad 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php @@ -80,10 +80,10 @@ class StyleTest extends ViewTestBase { $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->rowPlugin instanceof RowTest, 'Make sure the right row plugin class is loaded.'); + $this->assertTrue($view->style_plugin->row_plugin instanceof RowTest, 'Make sure the right row plugin class is loaded.'); $random_text = $this->randomName(); - $view->rowPlugin->setOutput($random_text); + $view->style_plugin->row_plugin->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.'); diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php index 98ae4f2e03a..ea3a87cf6d1 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewExecutableTest.php @@ -14,8 +14,6 @@ use Drupal\views\DisplayBag; 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; /** @@ -194,21 +192,6 @@ class ViewExecutableTest extends ViewUnitTestBase { $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'); } /** diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index 4a42a0ade00..898503f75db 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -211,13 +211,6 @@ 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. * @@ -678,17 +671,8 @@ class ViewExecutable { } } - // 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; - } + // Set the current display. + $this->current_display = $display_id; // Ensure requested display has a working handler. if (!$this->displayHandlers->has($display_id)) { @@ -1753,7 +1737,7 @@ class ViewExecutable { $this->style_plugin->destroy(); } - $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'); + $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'); foreach ($keys as $key) { unset($this->$key); } diff --git a/core/modules/views/tests/views_test_config/test_views/views.view.test_executable_displays.yml b/core/modules/views/tests/views_test_config/test_views/views.view.test_executable_displays.yml index c7f1ee27e72..83a217258b0 100644 --- a/core/modules/views/tests/views_test_config/test_views/views.view.test_executable_displays.yml +++ b/core/modules/views/tests/views_test_config/test_views/views.view.test_executable_displays.yml @@ -18,11 +18,6 @@ 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: '' diff --git a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/style/StyleTest.php b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/style/StyleTest.php index c1b0514229f..59dc396ad24 100644 --- a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/style/StyleTest.php +++ b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/style/StyleTest.php @@ -100,7 +100,7 @@ class StyleTest extends StylePluginBase { else { foreach ($this->view->result as $index => $row) { $this->view->row_index = $index; - $output .= $this->view->rowPlugin->render($row) . "\n"; + $output .= $this->row_plugin->render($row) . "\n"; } } diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php index f4b9f204770..80d1b7cb81a 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php @@ -864,15 +864,10 @@ class ViewEditFormController extends ViewFormControllerBase { * 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; @@ -896,7 +891,7 @@ class ViewEditFormController extends ViewFormControllerBase { break; case 'field': // Fetch the style plugin info so we know whether to list fields or not. - $style_plugin = $executable->style_plugin; + $style_plugin = $view->get('executable')->displayHandlers->get($display['id'])->getPlugin('style'); $uses_fields = $style_plugin && $style_plugin->usesFields(); if (!$uses_fields) { $build['fields'][] = array( @@ -910,7 +905,7 @@ class ViewEditFormController extends ViewFormControllerBase { case 'header': case 'footer': case 'empty': - if (!$executable->display_handler->usesAreas()) { + if (!$view->get('executable')->displayHandlers->get($display['id'])->usesAreas()) { $build[$type][] = array( '#markup' => t('The selected display type does not utilize @type plugins', array('@type' => $type)), '#theme_wrappers' => array('views_ui_container'), @@ -923,7 +918,7 @@ class ViewEditFormController extends ViewFormControllerBase { // Create an array of actions to pass to theme_links $actions = array(); - $count_handlers = count($executable->display_handler->getHandlers($type)); + $count_handlers = count($view->get('executable')->displayHandlers->get($display['id'])->getHandlers($type)); $actions['add'] = array( 'title' => t('Add'), 'href' => "admin/structure/views/nojs/add-item/{$view->id()}/{$display['id']}/$type", @@ -948,8 +943,8 @@ class ViewEditFormController extends ViewFormControllerBase { ), ); - if (!$executable->display_handler->isDefaultDisplay()) { - if (!$executable->display_handler->isDefaulted($types[$type]['plural'])) { + if (!$view->get('executable')->displayHandlers->get($display['id'])->isDefaultDisplay()) { + if (!$view->get('executable')->displayHandlers->get($display['id'])->isDefaulted($types[$type]['plural'])) { $build['#overridden'] = TRUE; } else { @@ -961,7 +956,7 @@ class ViewEditFormController extends ViewFormControllerBase { if (!isset($relationships)) { // Get relationship labels $relationships = array(); - foreach ($executable->display_handler->getHandlers('relationship') as $id => $handler) { + foreach ($view->get('executable')->displayHandlers->get($display['id'])->getHandlers('relationship') as $id => $handler) { $relationships[$id] = $handler->label(); } } @@ -970,7 +965,7 @@ class ViewEditFormController extends ViewFormControllerBase { $groups = array(); $grouping = FALSE; if ($type == 'filter') { - $group_info = $executable->display_handler->getOption('filter_groups'); + $group_info = $view->get('executable')->displayHandlers->get('default')->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. @@ -982,12 +977,12 @@ class ViewEditFormController extends ViewFormControllerBase { $build['fields'] = array(); - foreach ($executable->display_handler->getOption($types[$type]['plural']) as $id => $field) { + foreach ($view->get('executable')->displayHandlers->get($display['id'])->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 = $executable->display_handler->getHandler($type, $id); + $handler = $view->get('executable')->displayHandlers->get($display['id'])->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'])); @@ -1009,7 +1004,7 @@ class ViewEditFormController extends ViewFormControllerBase { $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 ($executable->display_handler->useGroupBy() && $handler->usesGroupBy()) { + if ($view->get('executable')->displayHandlers->get($display['id'])->useGroupBy() && $handler->usesGroupBy()) { $build['fields'][$id]['#settings_links'][] = l('' . t('Aggregation settings') . '', "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)); }