Commit b65c8f41 authored by catch's avatar catch

Issue #2198423 by damiankloip: Store the provider for Views plugins.

parent 40681d96
......@@ -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']);
......
......@@ -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']);
......
......@@ -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']);
......
......@@ -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.
......
......@@ -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()
......
......@@ -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']);
......
......@@ -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.
......
......@@ -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(),
);
......
......@@ -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');
......
......@@ -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.
......
......@@ -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);
......
......@@ -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)));
}
}
}
}
......@@ -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.');
}
/**
......
......@@ -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)));
}
}
}
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