Commit 2a941c13 authored by tim.plunkett's avatar tim.plunkett

Issue #1796156 by tim.plunkett, dawehner: Fixed usage of 'style_plugin' and 'row_plugin'.

parent 25fc6175
......@@ -240,8 +240,7 @@ public function attachTo($display_id) {
// Defer to the feed style; it may put in meta information, and/or
// attach a feed icon.
$name = $this->getOption('style_plugin');
$plugin = $this->getPlugin('style', $name);
$plugin = $this->getPlugin('style');
if ($plugin) {
$clone = $this->view->cloneView();
$clone->setDisplay($this->display['id']);
......
......@@ -662,8 +662,7 @@ public function validate() {
$errors = parent::validate();
if ($this->usesRowPlugin()) {
$name = $this->displayHandler->getOption('row_plugin');
$plugin = $this->displayHandler->getPlugin('row', $name);
$plugin = $this->displayHandler->getPlugin('row');
if (empty($plugin)) {
$errors[] = t('Style @style requires a row style but the row plugin is invalid.', array('@style' => $this->definition['title']));
}
......
<?php
/**
* @file
* Definition of Drupal\views\Tests\UI\RowUITest.
*/
namespace Drupal\views\Tests\UI;
/**
* Tests the UI of row plugins.
*
* @see Drupal\views_test_data\Plugin\views\row\RowTest.
*/
class RowUITest extends UITestBase {
public static function getInfo() {
return array(
'name' => 'Row: UI',
'description' => 'Tests the UI of row plugins.',
'group' => 'Views UI',
);
}
/**
* Tests changing the row plugin and changing some options of a row.
*/
public function testRowUI() {
$view = $this->getView();
$view_edit_url = "admin/structure/views/view/{$view->storage->name}/edit";
$row_plugin_url = "admin/structure/views/nojs/display/{$view->storage->name}/default/row";
$row_options_url = "admin/structure/views/nojs/display/{$view->storage->name}/default/row_options";
$this->drupalGet($row_plugin_url);
$this->assertFieldByName('row', 'fields', 'The default row plugin selected in the UI should be fields.');
$edit = array(
'row' => 'test_row'
);
$this->drupalPost(NULL, $edit, t('Apply'));
$this->assertFieldByName('row_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
$random_name = $this->randomName();
$edit = array(
'row_options[test_option]' => $random_name
);
$this->drupalPost(NULL, $edit, t('Apply'));
$this->drupalGet($row_options_url);
$this->assertFieldByName('row_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
$this->drupalPost($view_edit_url, array(), t('Save'));
$this->assertLink(t('Test row plugin'), 0, 'Make sure the test row plugin is shown in the UI');
$view = views_get_view($view->storage->name);
$view->initDisplay();
$row = $view->display_handler->getOption('row');
$this->assertEqual($row['type'], 'test_row', 'Make sure that the test_row got saved as used row plugin.');
$this->assertEqual($row['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.');
}
}
<?php
/**
* @file
* Definition of Drupal\views\Tests\UI\StyleUITest.
*/
namespace Drupal\views\Tests\UI;
/**
* Tests the UI of style plugins.
*
* @see Drupal\views_test_data\Plugin\views\style\StyleTest.
*/
class StyleUITest extends UITestBase {
public static function getInfo() {
return array(
'name' => 'Style: UI',
'description' => 'Tests the UI of style plugins.',
'group' => 'Views UI',
);
}
/**
* Tests changing the style plugin and changing some options of a style.
*/
public function testStyleUI() {
$view = $this->getView();
$view_edit_url = "admin/structure/views/view/{$view->storage->name}/edit";
$style_plugin_url = "admin/structure/views/nojs/display/{$view->storage->name}/default/style";
$style_options_url = "admin/structure/views/nojs/display/{$view->storage->name}/default/style_options";
$this->drupalGet($style_plugin_url);
$this->assertFieldByName('style', 'default', 'The default style plugin selected in the UI should be unformatted list.');
$edit = array(
'style' => 'test_style'
);
$this->drupalPost(NULL, $edit, t('Apply'));
$this->assertFieldByName('style_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
$random_name = $this->randomName();
$edit = array(
'style_options[test_option]' => $random_name
);
$this->drupalPost(NULL, $edit, t('Apply'));
$this->drupalGet($style_options_url);
$this->assertFieldByName('style_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
$this->drupalPost($view_edit_url, array(), t('Save'));
$this->assertLink(t('Test style plugin'), 0, 'Make sure the test style plugin is shown in the UI');
$view = views_get_view($view->storage->name);
$view->initDisplay();
$style = $view->display_handler->getOption('style');
$this->assertEqual($style['type'], 'test_style', 'Make sure that the test_style got saved as used style plugin.');
$this->assertEqual($style['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.');
}
}
......@@ -33,6 +33,29 @@ class RowTest extends RowPluginBase {
*/
public $output;
/**
* Overrides Drupal\views\Plugin\views\row\RowPluginBase::defineOptions().
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['test_option'] = array('default' => '');
return $options;
}
/**
* Overrides Drupal\views\Plugin\views\row\RowPluginBase::buildOptionsForm().
*/
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
$form['test_option'] = array(
'#type' => 'textfield',
'#description' => t('This is a textfield for test_option.'),
'#default_value' => $this->options['test_option'],
);
}
/**
* Sets the output property.
*
......
......@@ -33,6 +33,29 @@ class StyleTest extends StylePluginBase {
*/
public $output;
/**
* Overrides Drupal\views\Plugin\views\style\StylePluginBase::defineOptions().
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['test_option'] = array('default' => '');
return $options;
}
/**
* Overrides Drupal\views\Plugin\views\style\StylePluginBase::buildOptionsForm().
*/
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
$form['test_option'] = array(
'#type' => 'textfield',
'#description' => t('This is a textfield for test_option.'),
'#default_value' => $this->options['test_option'],
);
}
function usesRowPlugin() {
return parent::usesRowPlugin();
}
......
......@@ -917,8 +917,7 @@ public function getFormBucket($type, $display) {
break;
case 'field':
// Fetch the style plugin info so we know whether to list fields or not.
$style = $this->displayHandlers[$display['id']]->getOption('style');
$style_plugin = $this->displayHandlers[$display['id']]->getPlugin('style', $style['type']);
$style_plugin = $this->displayHandlers[$display['id']]->getPlugin('style');
$uses_fields = $style_plugin && $style_plugin->usesFields();
if (!$uses_fields) {
$build['fields'][] = array(
......
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