Skip to content
Snippets Groups Projects
Unverified Commit 32eb238f authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3231861 by Lendude, GuyPaddock: PHP errors when overriding the query settings

parent 81174ad7
No related branches found
No related tags found
12 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -326,8 +326,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$element = ['#parents' => ['query', 'options', 'query_tags']];
$value = explode(',', NestedArray::getValue($form_state->getValues(), $element['#parents']));
$value = array_filter(array_map('trim', $value));
$value = NestedArray::getValue($form_state->getValues(), $element['#parents']);
// When toggling a display to override defaults or vice-versa the submit
// handler gets invoked twice, and we don't want to bash the values from the
// original call.
if (is_array($value)) {
return;
}
$value = array_filter(array_map('trim', explode(',', $value)));
$form_state->setValueForElement($element, $value);
}
......
<?php
namespace Drupal\Tests\views\Functional\Plugin;
use Drupal\Tests\views\Functional\ViewTestBase;
/**
* Tests setting the query options.
*
* @group views
*/
class QueryOptionsTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_view'];
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = ['node', 'views_ui'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Test that query overrides are stored.
*/
public function testStoreQuerySettingsOverride() {
// Show the default display so the override selection is shown.
\Drupal::configFactory()->getEditable('views.settings')->set('ui.show.default_display', TRUE)->save();
$admin_user = $this->drupalCreateUser([
'administer views',
'administer site configuration',
]);
$this->drupalLogin($admin_user);
$edit = [];
$this->drupalGet('admin/structure/views/view/test_view/edit');
$this->submitForm($edit, 'Add Page');
$this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/query');
$this->assertSession()->checkboxNotChecked('query[options][distinct]');
$edit = [
'override[dropdown]' => 'page_1',
'query[options][distinct]' => 1,
];
$this->submitForm($edit, 'Apply');
$this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/query');
$this->assertSession()->checkboxChecked('query[options][distinct]');
$edit = [
'query[options][query_comment]' => 'comment',
'query[options][query_tags]' => 'query_tag, another_tag',
];
$this->submitForm($edit, 'Apply');
$this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/query');
$this->assertSession()->checkboxChecked('query[options][distinct]');
$this->assertSession()->fieldValueEquals('query[options][query_comment]', 'comment');
$this->assertSession()->fieldValueEquals('query[options][query_tags]', 'query_tag, another_tag');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment