Problem/Motivation
If you have a view with exposed filters that are grouped, and you change the identifier of the grouped filter (which the Views UI lets you do), you'll get something like the following PHP notice:
Notice: Undefined index: filename in Drupal\views\Plugin\views\filter\FilterPluginBase->acceptExposedInput() (line 1385 of core/modules/views/src/Plugin/views/filter/FilterPluginBase.php).
acceptExposedInput()
does this:
$value = $input[$this->options['expose']['identifier']];
But there's nothing in the $input
array with that identifier in this case.
Proposed resolution
Make sure we properly handle grouped filter identifiers, since they're different from the regular exposed filter identifiers:
if ($this->options['is_grouped']) {
$value = $input[$this->options['group_info']['identifier']];
}
else {
$value = $input[$this->options['expose']['identifier']];
}
Remaining tasks
Identify bug@see #10, #12, #13, #17Create test@see #25Fix bug@see #18, #25RTBC:#29: https://www.drupal.org/files/issues/2019-11-22/2884296-29.patch- Commit
User interface changes
-
API changes
-
Data model changes
-
Release notes snippet
-
Original report by @kallehauge
We never check if there is an input index for an exposed filter before we try to fetch it from the array of inputs in FilterPluginBase::acceptExposedInput which can causes notices for empty inputs:
$value = $input[$this->options['expose']['identifier']];
Further down in FilterPluginBase::acceptExposedInput we check if the $value variable is set. But at this point, we've already received a notice.
if (isset($value)) {
$this->value = $value;
if (empty($this->alwaysMultiple) && empty($this->options['expose']['multiple']) && !is_array($value)) {
$this->value = [$value];
}
}
Stack trace:
Notice: Undefined index: filename in Drupal\views\Plugin\views\filter\FilterPluginBase->acceptExposedInput() (line 1385 of core/modules/views/src/Plugin/views/filter/FilterPluginBase.php).
Drupal\views\Plugin\views\filter\FilterPluginBase->acceptExposedInput(Array) (Line: 1352)
Drupal\views\ViewExecutable->_build('filter') (Line: 1248)
Drupal\views\ViewExecutable->build(NULL) (Line: 1377)
Drupal\views\ViewExecutable->execute(NULL) (Line: 1440)
Drupal\views\ViewExecutable->render() (Line: 33)
Drupal\entity_browser\Plugin\views\display\EntityBrowser->execute() (Line: 1616)
Drupal\views\ViewExecutable->executeDisplay('entity_browser_1') (Line: 118)
Drupal\entity_browser\Plugin\EntityBrowser\Widget\View->getForm(Array, Object, Array) (Line: 127)
Drupal\entity_browser\Form\EntityBrowserForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('entity_browser_browse_files_modal_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('entity_browser_browse_files_modal_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comment | File | Size | Author |
---|---|---|---|
#29 | 2884296-29.patch | 2.96 KB | Lendude |
#29 | interdiff-2884296-25-28.txt | 522 bytes | Lendude |
#28 | interdiff_25_28.txt | 1.39 KB | anmolgoyal74 |
#28 | 2884296-28.patch | 3.8 KB | anmolgoyal74 |
#25 | 2884296-25.patch | 2.97 KB | Lendude |
Comments
Comment #2
kallehauge CreditAttribution: kallehauge as a volunteer and commentedComment #4
alduya CreditAttribution: alduya at 2DotsTwice bvba commentedI had the same error with an exposed, grouped filter in views.
The provided patch solved the problem.
As far as I could check, nothing else broke.
Comment #5
joelstein CreditAttribution: joelstein as a volunteer commentedI experienced the same error, but only if I changed the filter identifier on a grouped filter. This patch fixed it for me!
Comment #6
xjmThanks for working on this issue!
A few points of feedback:
ViewExecutable
, it doesn't look to me like it's valid to have an empty identifier for an exposed filter. Are there steps to reproduce this issue through the user interface using just core? @joelstein, maybe you could explain the steps to reproduce the bug as you encountered it?Drupal's coding standards specify that
else
should not be on the same line as the closing curly from the previous condition. Reference: https://www.drupal.org/docs/develop/standards/coding-standards#controlst...Thanks!
Comment #7
xjmComment #8
geek-merlinI had the same thing and the views exposed filter was malconfigured.
So i'd share xjm's view that IF there is a correctly configured view that triggers this, we have to debug the real issue behind that.
So if anyone checked all exposed filters and can upload an export of the view, we might be able to debug this.
Until that setting postponed.
Comment #10
DakwamineI could workaround the issue by setting the filter id of the grouped exposed filter to the expected index. For example, here was my notice:
My filter id was set by default on "bundle" (it was a taxonomy term) and when I changed the id to "type", the notice disappeared.
You can reproduce the issue like this:
Reproduction steps
Comment #12
wturrell CreditAttribution: wturrell commentedI can add a little more info on this.
- Like #4 and #5, patch fixes (or rather, at least, hides) the error.
- This is only a problem if you rename grouped exposed filters, not single.
This seems to happen whenever
expose.identifier
doesn't matchgroup_info.identifier
- the latter is correct, but as soon as you switch from single to grouped or vice-versa in the UI, the identifier of the inactive type is reset to the default.You can stop the error by manually editing the config and getting the two values in sync (but not via the UI for reason above).
My knowledge of views config is sketchy - EITHER:
- FilterPluginBase.php:acceptExposedInput() ought to check myfiltername.value (which is '0' for single, '1' for grouped) before deciding which key to read from $input - i.e. it should be checking $input[group_info.identifier] if value = 1
OR
- expose.identifier should be set to the same value as group_info.identifier when the filter is saved.
Is that enough for someone more cleverer than me to identify the correct fix?
Comment #13
Nick Hope CreditAttribution: Nick Hope commentedI also ran into this issue with grouped exposed filters in Views in D8.6.2.
What is strange is that I don't have the error on the site in my Pantheon dev environment. I only have it locally in Dev Desktop, with an imported copy of the Pantheon site.
The patch in the original post hides the errors for me too.
This was my error output, which I was getting on every page, not just the pages that include Views with grouped exposed filters:
Here are screen grabs of the filters that might be to blame. Note that I also have Better Exposed Filters on these Views, but only for the "Autosubmit" and "Hide submit button" features.
Comment #14
jigariusI tried the patch and it fixed the problem for me.
Comment #15
Kasey_MK CreditAttribution: Kasey_MK commented#13 worked for me, too. Thanks!
Comment #17
John Pitcairn CreditAttribution: John Pitcairn commentedI can confirm that changing the filter identifier for an exposed and grouped filter will produce this error.
In my case, the filter was also a combined-fields filter, but changing the filter identifier for an exposed combined-fields filter does not produce this error, unless the filter is also a grouped filter.
Comment #18
Rob Holmes CreditAttribution: Rob Holmes commentedJust ran into this issue as well, changing the filter identifier of a grouped filter causes the undefined index notices. This seems to solve it will add a patch if it pans out.
+ if ($this->options['is_grouped']) {
+ $value = $input[$this->options['group_info']['identifier']];
+ } else {
+ $value = $input[$this->options['expose']['identifier']];
+ }
Comment #20
Etroid CreditAttribution: Etroid commentedWhile working on https://www.drupal.org/project/better_exposed_filters/issues/3087939#com... I was able to confirm that @Rob-holmes' suggestion resolves the issue. I attached a patch with his suggested changes.
Comment #21
Nick Hope CreditAttribution: Nick Hope commentedThe patch in #20 works for me, with D8.7.8. I will start to use that rather than the original patch, as this one seems to tackle the root cause rather than just hiding the error. Thank you @Rob Holmes and @Etroid.
Issue needs a status change.
Comment #22
casey CreditAttribution: casey at SWIS commentedComment #23
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs commentedAdded test for #20.
Comment #24
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs commentedComment #25
LendudeThanks everyone for working on this and getting to the root of the problem!
While the fix in #20 fixes the notice, it leaves the filter broken since the actual filtering will still be done with the exposed identifier, so we need a second change to actually turn this into a working fix.
Added test coverage for this (which also revealed that #20 wasn't fixing everything yet).
Comment #27
dww@Lendude asked me to review this...
First of all, thanks to everyone who helped track down the actual problem here. Glad we didn't just try to suppress the error. Thanks @xjm for insisting on a real fix with a test. ;)
Next (as usual) thanks @Lendude for supplying a working test-only that demonstrates the bug! And supplying a complete fix, now that we understand the problem and have a test that exercises it.
Bot results are as expected: test-only fails, with-fix is passing. No code style problems.
Looking closely at #25, I like everything I see, except one tiny nitpick:
That's all I can possibly complain about. ;) Otherwise, I'd RTBC on the spot.
Thanks!
-Derek
Comment #28
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs commentedUpdated the patch in 25 with the point given in #27.
Comment #29
Lendude@anmolgoyal74 the changes in the other tests in #28 are out of the scope, we only need to modify it in the new test.
Edit: And thanks @dww for the review!
Comment #30
dww@anmolgoyal74 re: #28 - whoops, I didn't realize there were other
assertEquals(X, count(Y))
in the same test class. Good find, but yeah, out of scope. Would be a good novice follow-up issue to grep for that throughout core and change them all.@Lendude re: #29 - looks great, thanks! And you're welcome. ;)
RTBC #29: https://www.drupal.org/files/issues/2019-11-22/2884296-29.patch
Also fixing the title to match the actual bug, and providing a proper summary for core committers / posterity.
Thanks,
-Derek
Comment #31
Nick Hope CreditAttribution: Nick Hope commentedI'm currently running D8.7.10. I need both this patch and the patch at https://www.drupal.org/project/drupal/issues/2877061#comment-12102103 (#13) but they both modify the same file and cannot both be applied. I have been attempting to combine both patches but there is overlap/conflict and I'm not a coder so I don't have the skills to sort it out.
In this type of case, is it better to combine both patches and post here, or modify that other patch so that it works after this one has been applied? I'm not sure of the normal procedure.
Comment #32
dww@Nick Hope: At this point, this issue is RTBC. Hopefully it'll land soon. Posting "reroll backport combined with X" patches tend to confuse things and slow the process down (people queue things for the bots to test that can't possibly work, additional noise/comments for people asking for support with the combined patch, etc). So my vote is: no. Please don't post such a patch here.
However, I'd consider re-rolling #2877061: Illegal choice in grouped exposed filters with enabled option remember (ListField, BooleanOperator - Views filter handlers ) as if this has already been committed, then post that as a "DO-NOT-TEST-YET" patch over there. That issue is only "Needs work" right now, so there's little to no chance it'd land first. But if that patch is going to conflict with this, you could potentially help speed that issue up by having something ready-to-test once this is in Git. A preemptive re-roll of that issue for once this is committed.
Cheers,
-Derek
Comment #33
Nick Hope CreditAttribution: Nick Hope commented@dww Thank you. That makes sense. By the way it was me that changed that "illegal choice" issue from "8.6.x-dev Needs Review" to "8.9.x-dev Needs Work" last night. I may have another crack at an updated patch for that issue, but if any proficient coders feel like helping, feel free.
Pending a compatible patch for that issue, I suppose there's always the far-from-ideal fallback option of applying that patch #13 as is, together with the patch from the OP of this issue, since those 2 don't conflict.
Comment #34
alexpottCrediting @Dakwamine for commenting which very clear steps to reproduce the bug
Crediting @wturrell and @John Pitcairn for adding more info to solve the bug.
Crediting @Rob Holmes for posting a possible solution
Committed and pushed 1ab63529b2 to 9.0.x and 0ab34a4499 to 8.9.x. Thanks!
Comment #37
larowlanBackported to 8.8.x as this is non disruptive and a bug fix.
Comment #40
rick.kowal CreditAttribution: rick.kowal commentedI am on an older version of Drupal (not 8.9), so these patches didn't work for me. As a workaround fix, I exported the configs and found the problem index in the yml file for the view (key = identifier). I updated the yml file with my renamed key and imported the configuration and the error went away.