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

  1. Identify bug @see #10, #12, #13, #17
  2. Create test @see #25
  3. Fix bug @see #18, #25
  4. RTBC: #29: https://www.drupal.org/files/issues/2019-11-22/2884296-29.patch
  5. 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)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kallehauge created an issue. See original summary.

kallehauge’s picture

Title: Undefined index notice on empty filter text inputs » Undefined index notice on empty exposed filter text inputs in views

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alduya’s picture

I 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.

joelstein’s picture

Status: Active » Reviewed & tested by the community

I experienced the same error, but only if I changed the filter identifier on a grouped filter. This patch fixed it for me!

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for working on this issue!

A few points of feedback:

  1. In general, suppressing notices like this to ignore empty inputs can be caused by incorrect calling code or implementations, or can hide other bugs. Looking at where this method is called in 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?
  2. We need automated test coverage for bug fixes. If there are steps to reproduce, those steps are a starting point to writing a test that fails with HEAD and passes with a valid fix.
  3. If it does turn out that the fix in the patch is the best way to resolve the issue, there's also one small coding standards issue:
    +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
    @@ -1382,7 +1382,11 @@ public function acceptExposedInput($input) {
    +      } else {
    +        return FALSE;
    +      }
    

    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!

xjm’s picture

Issue tags: +Needs tests
geek-merlin’s picture

Status: Needs work » Postponed (maintainer needs more info)

I 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.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Dakwamine’s picture

I could workaround the issue by setting the filter id of the grouped exposed filter to the expected index. For example, here was my notice:

Notice: Undefined index: type in Drupal\views\Plugin\views\filter\FilterPluginBase->acceptExposedInput() (line 1385 of core/modules/views/src/Plugin/views/filter/FilterPluginBase.php).

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

  1. Start with fresh install.
  2. Login as admin.
  3. Enable the Media module.
  4. Create a new view of Media with a page.
  5. Add a Media type filter. For this filter:
    1. Click on Expose this filter to visitors....
    2. Click on Grouped filters radio button.
    3. Uncheck optional checkbox.
    4. Set Bundle identifier to "bundlea".
    5. Configure the first two groups with "is one of".
    6. Set a group as default.
    7. Click on Apply.
  6. Save the view.
  7. Go to /admin/config/development/logging and enable all errors.
  8. Go to the page of the view.
  9. A notice will trigger.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wturrell’s picture

I 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 match group_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?

Nick Hope’s picture

I 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:

Notice: Undefined index: source in Drupal\views\Plugin\views\filter\FilterPluginBase->acceptExposedInput() (line 1389 of core\modules\views\src\Plugin\views\filter\FilterPluginBase.php).

Drupal\views\Plugin\views\filter\FilterPluginBase->acceptExposedInput(Array) (Line: 306)
Drupal\views\Plugin\views\filter\InOperator->acceptExposedInput(Array) (Line: 159)
Drupal\views\Form\ViewsExposedForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('views_exposed_form', Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder->buildForm('views_exposed_form', Object) (Line: 135)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1238)
Drupal\views\ViewExecutable->build(NULL) (Line: 1391)
Drupal\views\ViewExecutable->execute() (Line: 167)
Drupal\facets\Plugin\facets\facet_source\SearchApiDisplay->fillFacetsWithResults(Array) (Line: 370)
Drupal\facets\FacetManager\DefaultFacetManager->updateResults('search_api:views_page__site_search__page_1') (Line: 94)
Drupal\facets_summary\FacetsSummaryManager\DefaultFacetsSummaryManager->build(Object) (Line: 91)
Drupal\facets_summary\Plugin\Block\FacetsSummaryBlock->build() (Line: 203)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func('Drupal\block\BlockViewBuilder::preRender', Array) (Line: 378)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 151)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 152)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 166)
Drupal\Core\Render\Renderer->renderPlaceholder('callback=Drupal%5Cblock%5CBlockViewBuilder%3A%3AlazyBuilder&args%5B0%5D=searchsummary&args%5B1%5D=full&args%5B2%5D&token=xMG4_7eYRIczuBvduIwThwhIhhuCExBoqz4sDgC18cw', Array) (Line: 696)
Drupal\big_pipe\Render\BigPipe->renderPlaceholder('callback=Drupal%5Cblock%5CBlockViewBuilder%3A%3AlazyBuilder&args%5B0%5D=searchsummary&args%5B1%5D=full&args%5B2%5D&token=xMG4_7eYRIczuBvduIwThwhIhhuCExBoqz4sDgC18cw', Array) (Line: 550)
Drupal\big_pipe\Render\BigPipe->sendPlaceholders(Array, Array, Object) (Line: 305)
Drupal\big_pipe\Render\BigPipe->sendContent(Object) (Line: 112)
Drupal\big_pipe\Render\BigPipeResponse->sendContent() (Line: 373)
Symfony\Component\HttpFoundation\Response->send() (Line: 20)

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.

Grouped exposed filter 1

Grouper exposed filter 2

jigarius’s picture

I tried the patch and it fixed the problem for me.

Kasey_MK’s picture

#13 worked for me, too. Thanks!

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

John Pitcairn’s picture

I 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.

Rob Holmes’s picture

Just 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']];
+ }

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Etroid’s picture

While 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.

Nick Hope’s picture

The 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.

casey’s picture

Status: Postponed (maintainer needs more info) » Needs work
anmolgoyal74’s picture

Added test for #20.

anmolgoyal74’s picture

Status: Needs work » Needs review
Lendude’s picture

Thanks 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).

The last submitted patch, 25: 2884296-25-TEST_ONLY.patch, failed testing. View results

dww’s picture

@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:

+++ b/core/modules/views/tests/src/Kernel/Handler/FilterInOperatorTest.php
@@ -164,6 +164,39 @@ public function testFilterNotInOperatorGroupedExposedSimple() {
+    $this->assertEquals(3, count($view->result));
$this->assertCount(3, $view->result);

That's all I can possibly complain about. ;) Otherwise, I'd RTBC on the spot.

Thanks!
-Derek

anmolgoyal74’s picture

Updated the patch in 25 with the point given in #27.

Lendude’s picture

@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!

dww’s picture

Title: Undefined index notice on empty exposed filter text inputs in views » Undefined index notice when renaming grouped filter identifiers
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

@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

Nick Hope’s picture

I'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.

dww’s picture

@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

Nick Hope’s picture

@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.

alexpott’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Crediting @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!

  • alexpott committed 1ab6352 on 9.0.x
    Issue #2884296 by Lendude, anmolgoyal74, kallehauge, Etroid, Nick Hope,...

  • alexpott committed 0ab34a4 on 8.9.x
    Issue #2884296 by Lendude, anmolgoyal74, kallehauge, Etroid, Nick Hope,...
larowlan’s picture

Status: Patch (to be ported) » Fixed

Backported to 8.8.x as this is non disruptive and a bug fix.

  • larowlan committed b8f580b on 8.8.x authored by alexpott
    Issue #2884296 by Lendude, anmolgoyal74, kallehauge, Etroid, Nick Hope,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rick.kowal’s picture

I 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.