Problem/Motivation
Adding a exposed filter to a view, and going to that view page leads to a notice, Notice: Undefined index: type in Drupal\views\Plugin\views\filter\Date->acceptExposedInput() (line 125 of core/modules/views/src/Plugin/views/filter/Date.php).
Date::acceptExposedInput is called two times in the views rendering build process (ViewsExecutable::build()) , first time through $exposed_form->renderExposedForm() and second time through $this->build('_filter'). Date::acceptExposedInput is aware that calling its parent will unset the 'type' property it's using, and thus try to restore it.
There's a few early return before the reset though, and when those early return hits, the second acceptExposedInput call won't find the array key it's looking for.
Proposed resolution
Restore the 'type' key before any early return in Drupal\views\Plugin\views\filter\Date::acceptExposedInput().
Steps to reproduce
Starting from a Standard profile installation:
- Go to /admin/config/development/logging , and display all messages.
- Go to /admin/structure/views/view/content
- Add a filter on the "Authored on" field, expose it to site visitors, saves the view
- Go to /admin/content
At this point, you'll be greeted with the aforementioned notice. Note that it doesn't show up in the view preview.
| Comment | File | Size | Author |
|---|---|---|---|
| #53 | 2811887-53.patch | 617 bytes | edwardsay |
| #34 | 2811887-34.patch | 2.09 KB | lendude |
| #34 | 2811887-34-TEST_ONLY.patch | 1.17 KB | lendude |
| #31 | 2811887-31-fix-tests-on-2369119-for-composer.patch | 2.99 KB | _Archy_ |
| #30 | 2811887-30-move-restore-overwritten-by-parent.patch | 891 bytes | louisnagtegaal |
Comments
Comment #2
DeFr commentedPatch implementing proposed resolution.
Comment #3
gcharles commentedI've also received this notice on a Development site that was updated from Drupal 8.10 to Drupal 8.2 . This notice shows on all Views Pages with exposed date filters. (Events, Meetings, Publications), practically everywhere i'm allowing the user to filter by Date/Time or Authored On dates. Once a date is selected(Jquery UI Date Picker) and the view is filtered, the notice disappears.
@DeFR's Patch solves this issue for my current installation.
Drupal 8.2
PHP 7 (Apache, MySQL etc)
Ubuntu 16.04
Comment #4
lendudeFix makes sense.
Lets update the comment while we are moving it by giving it a capital at the start.
Also, this needs tests.
Comment #5
ragnarkurm commentedTried the patch against 8.2 and it worked.
Comment #6
lendudeThis is discussed at some length in #2648950: [PP-2] Use form element of type date instead textfield when selecting a date in an exposed filter and that in turn defers to #2369119: Fatal error when trying to save a View with grouped filters using other than string values. Both those issues are MUCH bigger in scope then this, so I'll leave it open for now, but if any of those two issues land, this can be closed.
Comment #7
osmanI confirm the patch works.
Drupal 8.2.2
PHP 7.0.8 (MAMP)
Comment #8
pbcynth commentedPatch works. Thank you.
Drupal 8.2.2
PHP 5.6.15
WAMP
Comment #9
d.olaresko commentedActually, we don`t need this workaround with 'type' in acceptExposedInput() at all.
There is no exposed element that may change the value for 'type' and configured value is stored in $this->options['value']['type']
which is used in opBetween() and opSimple() only.
The patch that removes the workaround and changes the logic for op methods is attached and works for me on 8.2.3 and 8.3.x
Comment #10
drholera commentedComment #12
Andreas Radloff commentedWorks for me on 8.2.3
Comment #13
sdstyles commentedComment #14
mpdonadioThis is still Needs Work b/c the failing test in #9.
Comment #15
sdstyles commentedTrying to fix tests.
Comment #16
geerlingguy commentedFixes the notice for me, just found this in logs today and was happy to see the patch cleared everything up!
Comment #18
sdstyles commentedSeems some issues with CI tests.
Comment #19
cbccharlie commentedI applied this patch and the error disappeared when I edit the view. But when I go to the view (page or block), I see another error.
Comment #20
mpdonadioWith 8.3.0 looming, I think the usefulness of this patch is dwindling, and we need to get #2369119: Fatal error when trying to save a View with grouped filters using other than string values in as the long term fix, and then see what else we need to adjust.
Comment #22
mingsong#15 Patch of '2811887-19-fix-tests.patch' it works for me (Drupal core 8.2.5).
Here are some details about the view I am using with this patch:
Show type: Custom Entity type
Display: page
Format: Table
Fields: including date, string
Filter Criteria:
Created date (exposed)
Name string (exposed)
language code (exposed)
Filter plugin module(contributed): Better Exposed Filters
This patch both works on view editing and view page.
Thanks a lots
Comment #24
bkosborneFor what it's worth I have the patch applied from #2369119 (-145) and it doesn't appear to resolve this particular issue (it was mentioned it would in #6). I still get:
Notice: Undefined index: type in Drupal\views\Plugin\views\filter\Date->acceptExposedInput() (line 132 of core/modules/views/src/Plugin/views/filter/Date.php).Comment #25
mpdonadio#24, that surprises me a little, but in some ways it doesn't; #2369119: Fatal error when trying to save a View with grouped filters using other than string values is a really weird problem. @Lendude and I discussed both of these issues, along with some other related ones, at length. We decided to not officially postpone this, but we decided #2369119: Fatal error when trying to save a View with grouped filters using other than string values really needs to get in before we touch the same part of the code (and tests) in other issues, primarily because of the non-trivial merge conflicts that would result. That particular issue is soft- or hard-blocking about four or five others right now.
Comment #26
ashokshrestha commentedThis is not working for 8.2.6. Patch #15 worked me but only up to only 8.2.5 . Finding a solution for 8.2.6.
Comment #27
amykhailova commentedI can confirm that I am getting the same error on 8.2.6 with date filter in views not only grouped but also single filter on date that is of the type timestamp not string.
Comment #28
geerlingguy commentedAlso noticing the notice again now that 8.2.6 is out.
Comment #29
phonoman commentedSame. The patch did fine until 8.2.6. Receiving the notices on only one out of 3 views that use the same date setup..
Comment #30
louisnagtegaal commentedHello,
In our project we are using Drupal 8.2.6 and the patch from #15 did not solve the problem.
However when I inspected the code I saw that the original solution ("restore what got overwritten by the parent") seem to be placed on the wrong location, eg: after the return statements in the if-statements that checked the value and mix-max-values.
So if any of these if-statements applied, the "restore what got overwritten by the parent" was not applied and the second time the code was executed the above described notice was thrown.
My simple solution (move the "restore what got overwritten by the parent" to a place where it is always executed) is included in the attached patch, as explained above: this is for Drupal 8.2.6.
Comment #31
_Archy_ commentedUploading the modified version of the patch in #15 that applies with patch 2369119-145.patch from https://www.drupal.org/node/2369119. I need this for composer patching as I need both patches. Someone might also need it.
Comment #32
esod commentedAFAICT there's no difference difference between
2811887-2-exposed-date-restore-type-ealier.patchand2811887-30-move-restore-overwritten-by-parent.patchComment #33
mpdonadioJust assigning myself to triage this again in the next day or two, and try to touchbase with @Lendude.
Comment #34
lendudeDid a bit of debugging and using 8.4.x it is as @louisnagtegaal describes. When we return early in
\Drupal\views\Plugin\views\filter\Date::acceptExposedInputand acceptExposedInput gets called a second time (and on a normal page load it will get called more times then that), then things go wrong.An empty value will do, and because we submit the form on load (see #2568889: Views exposed text filter set to required shows an empty error and form error on page load) just loading the page will trigger the notice.
Test and a fix. I went back to just moving the restore logic. The fix direction from #9 will alter the data that is provided by the plugin and any plugins extending the Date filter should be able to rely on the correct data being there.
Comment #36
mpdonadioManually tested this, and all is good. Looked at patch, and no real feedback. We may end up adjusting the test in #2648950: [PP-2] Use form element of type date instead textfield when selecting a date in an exposed filter to be more robust, and match the changes that get introduced there, but this is fine to prevent any regressions for now.
Comment #38
alexpottCommitted 36c53a2 and pushed to 8.4.x. Thanks!
I think this should be ported to 8.3.x too.
All methods must have visibility - fixed on commit.
Comment #40
catch+1 for cherry-picking, trivial fix with test coverage.
Comment #41
alexpottCommitted d6afa76 and pushed to 8.3.x. Thanks!
Comment #43
yolker commentedTried the patch from @louisnagtegaal (#30) on Drupal 8.2.7 and it works. Thanks
Comment #45
synflag commentedHi,
i realised that there is still a notice, when you use "grouped filter".
Steps to reproduce:
- Change your views filter criteria to exposed and grouped
- go to /admin/reports/dblog
Sorry,
Lars
P.S.: We are using Drupal 8.4.5
Comment #46
yazzbe commentedYes, still a notice when using "grouped filter" as exposed filter.
Comment #47
andrezstar commentedSame here #45 #46
Comment #48
johnnny83 commentedAlso same here
Comment #49
johnnny83 commentedBy coincidence I got rid of the notice. After saving the grouped exposed filter there is a short warning below the views options that something is wrong with some selection (no specific details). Instead of saving the view I opened the filter again and saved it again. The short warning disappeared, I saved the view and the long notice on the view page also disappeared!
Comment #50
yazzbe commentedHi johnnny83. Tried your work around but couldn't figure it out.
I don't see the short warning, like you mentioned. But I tried to re-open the grouped filter after saving, saved it again, and then saved the view. But that didn't work. Still a notice.
Comment #51
johnnny83 commentedOk, try this:
1. Open the filter and change it to a single filter
2. Save filter
3. Save the view
4. Maybe clear cache (don't remember if I did it)
Then the same as before:
5. Open the filter again
6. Change it back to a grouped filter and put your options again
7. Save it
8. Open again
9. Save it
10. Save the view
Comment #52
yazzbe commentedTried #51, but that didn't work. But it led me to a cause and workaround.
My error notice looked like this:
Notice: Undefined index: min in Drupal\views\Plugin\views\filter\NumericFilter->acceptExposedInput() (line 416 of /data/sites/web/www/core/modules/views/src/Plugin/views/filter/NumericFilter.php)After opening the grouped filter and resetting it to a single filter, I noticed that the operator of the single filter previously was set to "is between". Which is not the default.
Fixed. No notice any more !!
NB: Somehow the previous value ("is between") of my "single filter" was still being used/checked and throwing a notice when converted to a grouped filter.
So make sure the value of a single filter is always set to "is equal to" before selecting the "grouped filter" option.
Hope this helps someone out.
Comment #53
edwardsay commentedI have created a small patch which removes this annoying notice:
Undefined index: type in Drupal\views\Plugin\views\filter\Date->acceptExposedInput()Comment #54
liquidcms commentedHave same issue with an exposed grouped date filter; work-arounds are great; but this issue shouldn't be marked as closed yet - sadly, it can't be re-opened.
Comment #55
tedfordgif commentedAdding to comment 52 above #2811887-52: Exposed date filter leads to a notice, the exposed identifiers for the un-grouped and grouped parts of the config also need to be the same.
Comment #56
damontgomery commentedSome pattern similar to #52 addressed the notices for us. Thanks!
Comment #57
kasey_mk commentedEDIT: Nevermind? This solution stopped working after a cache-clear.
Thanks johnnny83 - your notes helped fix the problem for me. I opened the .yml configuration file for my view and copied one of my grouped filter's operator & value settings into the default operator & value settings, did a config-import, and the error went away. E.g., in my case, see the "COPIED FROM group_items[1]" lines:
Comment #58
jennypanighetti commented#52 helped me! Thank you SO MUCH, it was driving me batty.