Skip to content
Snippets Groups Projects
Verified Commit c67eaad1 authored by Dave Long's avatar Dave Long
Browse files

Revert "Issue #2568889 by smustgrave, berenddeboer, Lendude, Anandhi Karnan,...

Revert "Issue #2568889 by smustgrave, berenddeboer, Lendude, Anandhi Karnan, ckaotik, boromino, diaodiallo, Yago Elias, yashingole, Abhijith S, Amber Himes Matz, dawehner, Scott Weston: Views exposed text filter set to required shows an empty error and form error on page load"

This reverts commit 9eae4f71.
parent ec92f543
No related branches found
No related tags found
17 merge requests!8506Draft: Issue #3456536 by ibrahim tameme,!5646Issue #3350972 by nod_: [random test failure]...,!5600Issue #3350972 by nod_: [random test failure]...,!5343Issue #3305066 by quietone, Rename RedirectLeadingSlashesSubscriber,!3603#ISSUE 3346218 Add a different message on edit comment,!3555Issue #2473873: Views entity operations lack cacheability support, resulting in incorrect dropbuttons,!3494Issue #3327018 by Spokje, longwave, xjm, mondrake: Update PHPStan to 1.9.3 and...,!3410Issue #3340128: UserLoginForm::submitForm has some dead code,!3389Issue #3325184 by Spokje, andypost, xjm, smustgrave: $this->configFactory is...,!3381Issue #3332363: Refactor Claro's menus-and-lists stylesheet,!3307Issue #3326193: CKEditor 5 can grow past the viewport when there is a lot of content,!3236Issue #3332419: Refactor Claro's messages stylesheet,!3231Draft: Issue #3049525 by longwave, fougere, larowlan, kim.pepper, AaronBauman, Wim...,!3212Issue #3294003: Refactor Claro's entity-meta stylesheet,!3194Issue #3330981: Fix PHPStan L1 error "Relying on entity queries to check access by default is deprecated...",!3143Issue #3313342: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 LayoutBuilderUiCacheContext.php on line 28,!2972Issue #1845004: Replace custom password hashing library with PHP 5.5 password_hash()
...@@ -246,32 +246,6 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) { ...@@ -246,32 +246,6 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) {
} }
} }
// Get an array of exposed filters and exposed required filters,
// keyed by identifier option.
$exposed_filters = [];
$exposed_required_filters = [];
foreach ($this->view->filter as $id => $handler) {
if ($handler->canExpose() && $handler->isExposed() && !empty($handler->options['expose']['identifier'])) {
if ($handler->options['expose']['required'] && $handler->options['plugin_id'] !== 'boolean') {
$exposed_required_filters[$handler->options['expose']['identifier']] = $id;
}
$exposed_filters[$handler->options['expose']['identifier']] = $id;
}
}
// If any required exposed filters loop through them to see if they have any
// input. If not don't auto process the form.
if (!empty($exposed_required_filters)) {
// Prevent form validation if exposed filter is not set.
$exposed_input = $this->view->getExposedInput();
foreach ($exposed_required_filters as $key => $required_filter) {
if (!$exposed_input || empty($exposed_input[$key])) {
$form_state->setAlwaysProcess(FALSE);
break;
}
}
}
if (!empty($this->options['reset_button'])) { if (!empty($this->options['reset_button'])) {
$form['actions']['reset'] = [ $form['actions']['reset'] = [
'#value' => $this->options['reset_button_label'], '#value' => $this->options['reset_button_label'],
...@@ -279,6 +253,13 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) { ...@@ -279,6 +253,13 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) {
'#weight' => 10, '#weight' => 10,
]; ];
// Get an array of exposed filters, keyed by identifier option.
$exposed_filters = [];
foreach ($this->view->filter as $id => $handler) {
if ($handler->canExpose() && $handler->isExposed() && !empty($handler->options['expose']['identifier'])) {
$exposed_filters[$handler->options['expose']['identifier']] = $id;
}
}
$all_exposed = array_merge($exposed_sorts, $exposed_filters); $all_exposed = array_merge($exposed_sorts, $exposed_filters);
// Set the access to FALSE if there is no exposed input. // Set the access to FALSE if there is no exposed input.
......
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- node.type.article
- node.type.page
- node.type.recipe
module:
- node
id: test_exposed_form_buttons_required
label: ''
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
display:
default:
id: default
display_title: Default
display_plugin: default
position: 0
display_options:
pager:
type: full
exposed_form:
type: input_required
options:
submit_button: Apply
reset_button: true
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
text_input_required: 'Select any filter and click on Apply to see results'
text_input_required_format: basic_html
access:
type: none
cache:
type: tag
filters:
type:
id: type
table: node_field_data
field: type
relationship: none
group_type: group
admin_label: ''
entity_type: node
entity_field: type
plugin_id: in_operator
operator: in
value:
all: all
article: article
page: page
group: 1
exposed: true
expose:
operator_id: type_op
label: 'Content: Type'
description: 'Exposed description'
use_operator: false
operator: ''
operator_limit_selection: false
operator_list: { }
identifier: type
required: true
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
author: '0'
editor: '0'
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
style:
type: default
row:
type: 'entity:node'
query:
type: views_query
options:
query_comment: ''
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
tags: { }
page_1:
id: page_1
display_title: Page
display_plugin: page
position: 0
display_options:
display_extenders: { }
path: test_exposed_form_buttons_required
cache_metadata:
max-age: -1
contexts:
- 'languages:language_interface'
- url
- url.query_args
- 'user.node_grants:view'
tags: { }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
use Drupal\Tests\views\Functional\ViewTestBase; use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\views\Entity\View;
/** /**
* Tests exposed forms functionality. * Tests exposed forms functionality.
...@@ -23,7 +24,7 @@ class ExposedFormTest extends ViewTestBase { ...@@ -23,7 +24,7 @@ class ExposedFormTest extends ViewTestBase {
* *
* @var array * @var array
*/ */
public static $testViews = ['test_exposed_form_buttons', 'test_exposed_form_buttons_required', 'test_exposed_block', 'test_exposed_form_sort_items_per_page', 'test_exposed_form_pager']; public static $testViews = ['test_exposed_form_buttons', 'test_exposed_block', 'test_exposed_form_sort_items_per_page', 'test_exposed_form_pager'];
/** /**
* Modules to enable. * Modules to enable.
...@@ -299,27 +300,23 @@ public function providerTestExposedBlock() { ...@@ -299,27 +300,23 @@ public function providerTestExposedBlock() {
* Tests the input required exposed form type. * Tests the input required exposed form type.
*/ */
public function testInputRequired() { public function testInputRequired() {
$this->drupalGet('test_exposed_form_buttons_required'); $view = View::load('test_exposed_form_buttons');
$display = &$view->getDisplay('default');
$display['display_options']['exposed_form']['type'] = 'input_required';
$view->save();
$this->drupalGet('test_exposed_form_buttons');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$this->helperButtonHasLabel('edit-submit-test-exposed-form-buttons-required', 'Apply'); $this->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', 'Apply');
// Ensure that no results are displayed by default when no input is // Ensure that no results are displayed by default when no input is
// provided. // provided.
$this->assertSession()->elementNotExists('xpath', "//div[contains(@class, 'views-row')]"); $this->assertSession()->elementNotExists('xpath', "//div[contains(@class, 'views-row')]");
// Ensure that no error element is shown.
$this->assertSession()->elementNotExists('css', '.messages--error'); $this->drupalGet('test_exposed_form_buttons', ['query' => ['type' => 'article']]);
$this->assertFalse($this->getSession()->getPage()->findField('type')->hasClass('error'));
$edit = [
'type' => 'article',
];
$this->submitForm($edit, 'Apply');
// Ensure that results are displayed by default when input is provided. // Ensure that results are displayed by default when input is provided.
$this->assertSession()->elementsCount('xpath', "//div[contains(@class, 'views-row')]", 5); $this->assertSession()->elementsCount('xpath', "//div[contains(@class, 'views-row')]", 5);
// Test exposed filter on preview.
$this->drupalGet('admin/structure/views/view/test_view/test_exposed_form_buttons_required');
$this->assertSession()->elementNotExists('css', '.messages--error');
} }
/** /**
...@@ -330,6 +327,7 @@ public function testTextInputRequired() { ...@@ -330,6 +327,7 @@ public function testTextInputRequired() {
$display = &$view->storage->getDisplay('default'); $display = &$view->storage->getDisplay('default');
$display['display_options']['exposed_form']['type'] = 'input_required'; $display['display_options']['exposed_form']['type'] = 'input_required';
// Set up the "on demand text". // Set up the "on demand text".
// @see https://www.drupal.org/node/535868
$on_demand_text = 'Select any filter and click Apply to see results.'; $on_demand_text = 'Select any filter and click Apply to see results.';
$display['display_options']['exposed_form']['options']['text_input_required'] = $on_demand_text; $display['display_options']['exposed_form']['options']['text_input_required'] = $on_demand_text;
$display['display_options']['exposed_form']['options']['text_input_required_format'] = filter_default_format(); $display['display_options']['exposed_form']['options']['text_input_required_format'] = filter_default_format();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment