Problem/Motivation

Views exposed form throws PHP warnings on AJAX reset. The form having between field of date.

<br/><b>Warning</b>:  Undefined array key "min" in <b>/var/www/html/web/core/modules/views/src/Plugin/views/filter/NumericFilter.php</b> on line <b>454</b><br/><br/><b>Warning</b>:  Undefined array key "min" in <b>/var/www/html/web/core/modules/views/src/Plugin/views/filter/Date.php</b> on line <b>147</b><br/><br/><b>Warning</b>:  Undefined array key "max" in <b>/var/www/html/web/core/modules/views/src/Plugin/views/filter/Date.php</b> on line <b>147</b><br/>[
    {

Steps to reproduce

  • Create view page
  • Add Date filter and set to exposed
  • Add Date filter and group
  • - +7 days
  • - + 30 days
  • Set dates, apply.

Proposed resolution

In file:
web/core/modules/views/src/Plugin/views/filter/NumericFilter.php:454
Change to:
if (empty($value['min']) && empty($value['max'])) {

In file:
web/core/modules/views/src/Plugin/views/filter/Date.php:147
Change to:
if (empty($this->value['min']) && empty($this->value['max'])) {

Remaining tasks

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3389478

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

_renify_ created an issue. See original summary.

_renify_’s picture

StatusFileSize
new728 bytes
cilefen’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thank for reporting.

We will need a test to show this issue, but also may need to dig deeper. Typically these kind of issues putting an isset or !empty is masking an actual problem.

_renify_’s picture

StatusFileSize
new670 bytes

There is error message encounter on 3389478-date-1.patch so i uploaded new patch.

dieterholvoet’s picture

I think adding those empty() calls is enough here, since the same check is being done in the child method Drupal\views\Plugin\views\filter\Date::acceptExposedInput():

if ($operators[$operator]['values'] == 1) {
  // When the operator is either <, <=, =, !=, >=, > or regular_expression
  // the input contains only one value.
  if ($this->value['value'] == '') {
    return FALSE;
  }
}
elseif ($operators[$operator]['values'] == 2) {
  // When the operator is either between or not between the input contains
  // two values.
  if (empty($this->value['min']) || empty($this->value['max'])) {
    return FALSE;
  }
}

dieterholvoet’s picture

DieterHolvoet changed the visibility of the branch 10.1.x to hidden.

dieterholvoet’s picture

Issue summary: View changes

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

shalini_jha made their first commit to this issue’s fork.

adriancid’s picture

StatusFileSize
new1.25 KB

arunkumark made their first commit to this issue’s fork.

arunkumark’s picture

Title: Warning: Undefined array key "min" in Drupal\views\Plugin\views\filter\NumericFilter->acceptExposedInput() (line 437 of core/modules/views/src/Plugin/views/filter/NumericFilter.php) » [Views exposed filter] - Warnings on Date filter min & max
Issue summary: View changes

Updated issue summary as per issue summary document.

arunkumark’s picture

Status: Needs work » Needs review
StatusFileSize
new607.54 KB

Run the PHPUnit locally, Not getting any errors. But getting errors in the git pipeline.

Apply patch

smustgrave’s picture

Status: Needs review » Needs work

Previously tagged for tests so moving back for those

Did not review.

arunkumark changed the visibility of the branch 3389478-warning-undefined-array-11.x to hidden.

arunkumark changed the visibility of the branch 3389478-warning-undefined-array-11.x to active.

arunkumark changed the visibility of the branch 3389478-warning-undefined-array to hidden.

arunkumark’s picture

Status: Needs work » Needs review

Added empty condition for date filter and test for MIN and MAX empty on date filter.

smustgrave’s picture

Status: Needs review » Needs work

Believe the tests need some work as the test-only feature is passing when it should fail.

arunkumark’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Test-only is still passing when it should be failing.

arunkumark’s picture

@smustgrave
Verified the Failing jobs are irrelated to the changes. After syncing the latest 11.x branch the issue was resolved.

shalini_jha’s picture

I have investigated this test case and observed that the warning appears only under specific conditions. Initially, when we add a date as an exposed filter and select the 'Between' operator, the warning does not appear upon saving the view. However, if we edit the date exposed filter, switch from 'single filter' to 'group filters,' and again select the 'Between' operator for the group filters, saving the view triggers the warning. When we access the view page and select the 'All' option, the warning arises because the single filter operator is still set to 'Between,' but the 'min' and 'max' values are not available for the 'All' option.

To demonstrate this behaviour, I modified the test case to show the warning. After applying the solution, the test case passes successfully. Please review and let me know .

shalini_jha’s picture

Status: Needs work » Needs review
arunkumark’s picture

@shalini_jha It seems the pipeline issue was random. After rerunning it, it was resolved. I also verified the file; it was irrelevant to the change made.

smustgrave’s picture

Status: Needs review » Needs work

2 nitpick comments.

shalini_jha’s picture

Assigned: Unassigned » shalini_jha
shalini_jha’s picture

Assigned: shalini_jha » Unassigned

i have addressed the feedback. and updated the MR , it seems again pipeline fail with not related to this changes.

shalini_jha’s picture

Status: Needs work » Needs review

I have re running the pipeline and now it is fixed. so moving this for NR. Kindly review.

mauriciopieper’s picture

StatusFileSize
new5.12 KB

This issue also happens when you use values for date fields instead of the range option (min/max), but when doing that, it throws the warning on the key 'value':

Warning: Undefined array key "value" in Drupal\views\Plugin\views\filter\NumericFilter->acceptExposedInput() (line 448 of core/modules/views/src/Plugin/views/filter/NumericFilter.php).

I am adding a patch because I do not want to commit the changes to the MR since it is already under review. However, I believe it makes sense to address that as part of this issue. In that case, we would probably need to update the issue's title to be more precise.

oily’s picture

#34 I think should be created as a child issue. There is still considerable work required to complete this issue in itself.

The test-only feature is now working correctly.

Removing the Needs tests tag.

oily’s picture

Issue tags: -Needs tests

oily changed the visibility of the branch 3389478-warning-undefined-array-11.x to hidden.

oily changed the visibility of the branch 10.1.x to active.

oily changed the visibility of the branch 10.1.x to hidden.

oily changed the visibility of the branch 3389478-warning-undefined-array-11.x to active.

oily changed the visibility of the branch 3389478-warning-undefined-array-11.x to hidden.

oily changed the visibility of the branch 10.1.x to active.

oily changed the visibility of the branch 3389478-warning-undefined-array to active.

oily changed the visibility of the branch 11.x to hidden.

oily changed the visibility of the branch 10.1.x to hidden.

oily changed the visibility of the branch 3389478-warning-undefined-array to hidden.

oily changed the visibility of the branch 3389478-warning-undefined-array-11.x to active.

oily’s picture

Rebased MR. Pipeline tests are green.

oily’s picture

Issue summary: View changes
oily’s picture

Issue tags: +Needs screenshots

Needs before and after screenshots

oily’s picture

Status: Needs review » Needs work
shalini_jha’s picture

Status: Needs work » Needs review

Thank you for your review. Since this issue is related to the warning and the test already displays the warning message without any UI changes, is it still necessary to include a screenshot for this?

oily’s picture

Okay I will remove it. I have not reproduced the issue yet. So long as it can be reproduced using the steps it should be okay.

oily’s picture

Issue tags: -Needs screenshots
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Believe feedback has been addressed.

Not super liking having to do all the manual changes vs having a view already setup but seems to be how it's already setup.

Tests are still showing coverage https://git.drupalcode.org/issue/drupal-3389478/-/jobs/3697086

Replicated this is fixed manually following steps in summary, so LGTM.

quietone’s picture

Title: [Views exposed filter] - Warnings on Date filter min & max » Views exposed filter warnings on Date filter min & max
catch’s picture

Status: Reviewed & tested by the community » Needs work

I think this should use a strict comparison so that it handles '0' correctly.

matthiasm11’s picture

Status: Needs work » Closed (duplicate)

The PR from #3294700: Date filter shows error in view exposed group filter with multiple select option contains almost the same solution, but already handles the strict comparison.
I propose to use the fix from #3294700: Date filter shows error in view exposed group filter with multiple select option and close this issue.