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
Comments
Comment #2
_renify_ commentedComment #3
cilefen commentedComment #4
smustgrave commentedThank 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.
Comment #5
_renify_ commentedThere is error message encounter on 3389478-date-1.patch so i uploaded new patch.
Comment #6
dieterholvoet commentedI think adding those
empty()calls is enough here, since the same check is being done in the child methodDrupal\views\Plugin\views\filter\Date::acceptExposedInput():Comment #8
dieterholvoet commentedComment #10
dieterholvoet commentedComment #14
adriancidComment #16
arunkumarkUpdated issue summary as per issue summary document.
Comment #17
arunkumarkRun the PHPUnit locally, Not getting any errors. But getting errors in the git pipeline.
Comment #18
smustgrave commentedPreviously tagged for tests so moving back for those
Did not review.
Comment #22
arunkumarkAdded empty condition for date filter and test for MIN and MAX empty on date filter.
Comment #23
smustgrave commentedBelieve the tests need some work as the test-only feature is passing when it should fail.
Comment #24
arunkumarkComment #25
smustgrave commentedTest-only is still passing when it should be failing.
Comment #26
arunkumark@smustgrave
Verified the Failing jobs are irrelated to the changes. After syncing the latest 11.x branch the issue was resolved.
Comment #27
shalini_jha commentedI 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 .
Comment #28
shalini_jha commentedComment #29
arunkumark@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.
Comment #30
smustgrave commented2 nitpick comments.
Comment #31
shalini_jha commentedComment #32
shalini_jha commentedi have addressed the feedback. and updated the MR , it seems again pipeline fail with not related to this changes.
Comment #33
shalini_jha commentedI have re running the pipeline and now it is fixed. so moving this for NR. Kindly review.
Comment #34
mauriciopieper commentedThis 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.
Comment #35
oily commented#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.
Comment #36
oily commentedComment #48
oily commentedRebased MR. Pipeline tests are green.
Comment #49
oily commentedComment #50
oily commentedNeeds before and after screenshots
Comment #51
oily commentedComment #52
shalini_jha commentedThank 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?
Comment #53
oily commentedOkay 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.
Comment #54
oily commentedComment #55
smustgrave commentedBelieve 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.
Comment #56
quietone commentedComment #57
catchI think this should use a strict comparison so that it handles '0' correctly.
Comment #58
matthiasm11 commentedThe 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.