In a view with some exposed filters that have custom identifiers I get lots of undefined index warnings like the following:

Undefined index: my_custom_identifier in Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->exposedFormAlter() (line 1172 ...

The filter handler array is keyed on the original field identifier rather than the custom identifier, so the code that checks if the operator is exposed needs to use the $label from BEF settings instead of the custom element Id.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Peacog created an issue. See original summary.

Peacog’s picture

Status: Active » Needs review
FileSize
1.02 KB

Here's a patch that squashes the warnings

matthieuscarset’s picture

Thank you @Peacog

This patch works like a charm.

matthieuscarset’s picture

Status: Needs review » Reviewed & tested by the community
rlhawk’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

I'm not having any luck reproducing this bug. Can you give precise instructions for how to reproduce it? Thanks.

Peacog’s picture

FileSize
29.86 KB

It's been a while since I looked at this, but as far as I remember all you have to do is change the default filter identifier for the exposed filter to something else. Like this:
Custom filter identifier

Peacog’s picture

Status: Postponed (maintainer needs more info) » Needs review
Peacog’s picture

Title: Undefined index checking for exposed operator on filters with custom identifiers » Exposed operator on a filter with a custom identifier not handled correctly
FileSize
1.16 KB

The latest dev version gets rid of the error message, but there is still a problem handling exposed operators for filters with custom identifiers. To reproduce the problem try this configuration:

  1. Create a node view with a Has taxonomy terms filter
  2. Expose the filter and change the default filter identifier from tid to something else, for example myterm
  3. In BEF settings select the Checkboxes/Radio Buttons filter type
  4. Tick the Make this filter collapsible option.
  5. That's it. Now at line 1218 in BetterExposedFilters.php the piece of code that should run if the operator is exposed for the filter will never be executed because it's looking for the custom field id 'myterm' in the handlers array instead of 'tid'. You can use $label instead of $field_id to solve the problem.

rlhawk’s picture

Status: Needs review » Reviewed & tested by the community

The latest patch fixes the issue. Thanks.

  • rlhawk committed 3298924 on 8.x-3.x authored by Peacog
    Issue #2902323 by Peacog, matthieuscarset, rlhawk: Exposed operator on a...
rlhawk’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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