From b65c8f413d085509d8682d6aa0fa8dda3bafbb0b Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Wed, 19 Feb 2014 16:59:12 +0000 Subject: [PATCH] Issue #2198423 by damiankloip: Store the provider for Views plugins. --- .../comment/Plugin/views/wizard/Comment.php | 3 ++ .../Drupal/file/Plugin/views/wizard/File.php | 1 + .../Drupal/node/Plugin/views/wizard/Node.php | 1 + .../node/Plugin/views/wizard/NodeRevision.php | 1 + .../Drupal/rest/Tests/CollectRoutesTest.php | 2 +- .../Plugin/views/wizard/TaxonomyTerm.php | 1 + .../Drupal/user/Plugin/views/wizard/Users.php | 1 + .../views/lib/Drupal/views/Entity/View.php | 2 + .../views/display/DisplayPluginBase.php | 6 ++- .../Plugin/views/wizard/WizardPluginBase.php | 1 + .../Drupal/views/Tests/Plugin/DisplayTest.php | 2 + .../Drupal/views/Tests/Wizard/BasicTest.php | 14 ++++-- .../lib/Drupal/views_ui/Tests/DisplayTest.php | 8 ++++ .../Drupal/views_ui/Tests/ViewEditTest.php | 45 +++++++++++++++++++ 14 files changed, 82 insertions(+), 6 deletions(-) diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/views/wizard/Comment.php b/core/modules/comment/lib/Drupal/comment/Plugin/views/wizard/Comment.php index e63ae1558680..09fb54e2f1df 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/views/wizard/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/views/wizard/Comment.php @@ -140,12 +140,15 @@ protected function defaultDisplayOptions() { // Add permission-based access control. $display_options['access']['type'] = 'perm'; + $display_options['access']['provider'] = 'user'; // Add a relationship to nodes. $display_options['relationships']['node']['id'] = 'node'; $display_options['relationships']['node']['table'] = 'comment'; $display_options['relationships']['node']['field'] = 'node'; $display_options['relationships']['node']['required'] = 1; + $display_options['relationships']['node']['plugin_id'] = 'standard'; + $display_options['relationships']['node']['provider'] = 'views'; // Remove the default fields, since we are customizing them here. unset($display_options['fields']); diff --git a/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php b/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php index 00fb296eeb08..94529a0b82a1 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php +++ b/core/modules/file/lib/Drupal/file/Plugin/views/wizard/File.php @@ -44,6 +44,7 @@ protected function defaultDisplayOptions() { // Add permission-based access control. $display_options['access']['type'] = 'perm'; + $display_options['access']['provider'] = 'user'; // Remove the default fields, since we are customizing them here. unset($display_options['fields']); diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php b/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php index ffff6a5ca2b3..a5c2e3538606 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php @@ -125,6 +125,7 @@ protected function defaultDisplayOptions() { // Add permission-based access control. $display_options['access']['type'] = 'perm'; + $display_options['access']['provider'] = 'user'; // Remove the default fields, since we are customizing them here. unset($display_options['fields']); diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/wizard/NodeRevision.php b/core/modules/node/lib/Drupal/node/Plugin/views/wizard/NodeRevision.php index d4c31cba05a8..7c0e5de23822 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/wizard/NodeRevision.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/wizard/NodeRevision.php @@ -88,6 +88,7 @@ protected function defaultDisplayOptions() { // Add permission-based access control. $display_options['access']['type'] = 'perm'; + $display_options['access']['provider'] = 'user'; $display_options['access']['perm'] = 'view revisions'; // Remove the default fields, since we are customizing them here. diff --git a/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php b/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php index 05c6d5d0dfe7..0d6f0eda8040 100644 --- a/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php +++ b/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php @@ -103,7 +103,7 @@ protected function setUp() { $display_manager->expects($this->once()) ->method('getDefinition') - ->will($this->returnValue($this->restExport)); + ->will($this->returnValue(array('id' => 'test', 'provider' => 'test'))); $none = $this->getMockBuilder('\Drupal\views\Plugin\views\access\None') ->disableOriginalConstructor() diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/wizard/TaxonomyTerm.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/wizard/TaxonomyTerm.php index fa4bfa1dbe7e..1c345113400d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/wizard/TaxonomyTerm.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/wizard/TaxonomyTerm.php @@ -42,6 +42,7 @@ protected function defaultDisplayOptions() { // Add permission-based access control. $display_options['access']['type'] = 'perm'; + $display_options['access']['provider'] = 'user'; // Remove the default fields, since we are customizing them here. unset($display_options['fields']); diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/wizard/Users.php b/core/modules/user/lib/Drupal/user/Plugin/views/wizard/Users.php index 36de93d4947f..37c9a5c7b980 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/wizard/Users.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/wizard/Users.php @@ -64,6 +64,7 @@ protected function defaultDisplayOptions() { // Add permission-based access control. $display_options['access']['type'] = 'perm'; + $display_options['access']['provider'] = 'user'; $display_options['access']['perm'] = 'access user profiles'; // Remove the default fields, since we are customizing them here. diff --git a/core/modules/views/lib/Drupal/views/Entity/View.php b/core/modules/views/lib/Drupal/views/Entity/View.php index f9e4b07d5393..a5d9ea84983c 100644 --- a/core/modules/views/lib/Drupal/views/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Entity/View.php @@ -176,6 +176,7 @@ public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) { } $plugin = Views::pluginManager('display')->getDefinition($plugin_id); + if (empty($plugin)) { $plugin['title'] = t('Broken'); } @@ -208,6 +209,7 @@ public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) { 'id' => $id, 'display_title' => $title, 'position' => count($this->display), + 'provider' => $plugin['provider'], 'display_options' => array(), ); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index 9737c182a832..72d27253eacf 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -2234,7 +2234,11 @@ public function submitOptionsForm(&$form, &$form_state) { $plugin = Views::pluginManager($plugin_type)->createInstance($form_state['values'][$plugin_type]['type']); if ($plugin) { $plugin->init($this->view, $this, $plugin_options['options']); - $plugin_options = array('type' => $form_state['values'][$plugin_type]['type'], 'options' => $plugin->options); + $plugin_options = array( + 'type' => $form_state['values'][$plugin_type]['type'], + 'options' => $plugin->options, + 'provider' => $plugin->definition['provider'] + ); $this->setOption($plugin_type, $plugin_options); if ($plugin->usesOptions()) { $form_state['view']->addFormToStack('display', $this->display['id'], $plugin_type . '_options'); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php index e741f3a2dcf7..1521e2fe81e6 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php @@ -760,6 +760,7 @@ protected function defaultDisplayOptions() { // Add default options array to each plugin type. foreach ($display_options as &$options) { $options['options'] = array(); + $options['provider'] = 'views'; } // Add a least one field so the view validates and the user has a preview. diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php index 30dd97531eb6..61d261174ba1 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -72,6 +72,7 @@ public function testDisplayPlugin() { 'id' => 'display_test_1', 'display_title' => 'Display test', 'position' => 1, + 'provider' => 'views_test_data', ); $this->assertEqual($displays['display_test_1'], $options); @@ -84,6 +85,7 @@ public function testDisplayPlugin() { 'id' => 'display_test_2', 'display_title' => 'Display test 2', 'position' => 2, + 'provider' => 'views_test_data', ); $this->assertEqual($displays['display_test_2'], $options); diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/BasicTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/BasicTest.php index 2a6787853326..987e9a897287 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/BasicTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/BasicTest.php @@ -7,6 +7,8 @@ namespace Drupal\views\Tests\Wizard; +use Drupal\Component\Utility\String; + /** * Tests creating views with the wizard and viewing them on the listing page. */ @@ -170,11 +172,15 @@ public function testWizardDefaultValues() { // @see \Drupal\views\Tests\Plugin\DisplayUnitTest $view = views_get_view($random_id); $displays = $view->storage->get('display'); - foreach (array('query', 'exposed_form', 'pager', 'style', 'row') as $type) { - foreach ($displays as $display) { - $this->assertFalse(empty($display['display_options'][$type]['options']), format_string('Default options found for @plugin.', array('@plugin' => $type))); + + foreach ($displays as $display) { + $this->assertIdentical($display['provider'], 'views', 'Expected provider found for display.'); + + foreach (array('query', 'exposed_form', 'pager', 'style', 'row') as $type) { + $this->assertFalse(empty($display['display_options'][$type]['options']), String::format('Default options found for @plugin.', array('@plugin' => $type))); + $this->assertIdentical($display['display_options'][$type]['provider'], 'views', String::format('Expected provider found for @plugin.', array('@plugin' => $type))); } } - } + } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayTest.php index eaa9f1d8e4c3..7ed907bae3ad 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayTest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayTest.php @@ -111,6 +111,14 @@ public function testAddDisplay() { $this->assertNoLink('Master*', 0, 'Make sure the master display is not marked as changed.'); $this->assertLink('Page*', 0, 'Make sure the added display is marked as changed.'); + + $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/path", array('path' => 'test/path'), t('Apply')); + $this->drupalPostForm(NULL, array(), t('Save')); + + // Test that the new view display contains the correct provider. + $view = Views::getView($view['id']); + $displays = $view->storage->get('display'); + $this->assertIdentical($displays['page_1']['provider'], 'views', 'The expected provider was added to the new display.'); } /** diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewEditTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewEditTest.php index 12aae9198c3b..e1036a0b25d9 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewEditTest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewEditTest.php @@ -7,7 +7,9 @@ namespace Drupal\views_ui\Tests; +use Drupal\Component\Utility\String; use Drupal\views\Plugin\Core\Entity\View; +use Drupal\views\Views; /** * Tests some general functionality of editing views, like deleting a view. @@ -113,4 +115,47 @@ public function testEditFormOtherOptions() { $this->assertFieldByName('field_langcode_add_to_query', TRUE); } + /** + * Tests that plugins selected from the view edit form contain providers. + */ + public function testPluginProviders() { + $plugin_data = array( + 'access' => array( + 'value' => 'test_static', + 'provider' => 'views_test_data', + ), + 'cache' => array( + 'value' => 'time', + 'provider' => 'views', + ), + 'exposed_form' => array( + 'value' => 'input_required', + 'provider' => 'views', + ), + 'pager' => array( + 'value' => 'full', + 'provider' => 'views', + ), + 'row' => array( + 'value' => 'test_row', + 'provider' => 'views_test_data', + ), + 'style' => array( + 'value' => 'test_style', + 'provider' => 'views_test_data', + ), + ); + + foreach ($plugin_data as $plugin_type => $plugin_options) { + $element_name = $plugin_type . '[type]'; + // Save the plugin form, to change the plugin used. + $this->drupalPostForm("admin/structure/views/nojs/display/test_view/default/$plugin_type", array($element_name => $plugin_options['value']), t('Apply')); + $this->drupalPostForm('admin/structure/views/view/test_view', array(), t('Save')); + // Check the plugin provider. + $view = Views::getView('test_view'); + $displays = $view->storage->get('display'); + $this->assertIdentical($displays['default']['display_options'][$plugin_type]['provider'], $plugin_options['provider'], String::format('Expected provider found for @plugin.', array('@plugin' => $plugin_type))); + } + } + } -- GitLab