Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#8 | bef-exposed-operator-custom-filter-id-2902323-8.patch | 1.16 KB | Peacog |
#2 | bef-undefined-index-checking-exposed-operator-2902323-2.patch | 1.02 KB | Peacog |
Comments
Comment #2
Peacog CreditAttribution: Peacog as a volunteer commentedHere's a patch that squashes the warnings
Comment #3
matthieuscarset CreditAttribution: matthieuscarset as a volunteer and at Appnovation commentedThank you @Peacog
This patch works like a charm.
Comment #4
matthieuscarset CreditAttribution: matthieuscarset as a volunteer and at Appnovation commentedComment #5
rlhawkI'm not having any luck reproducing this bug. Can you give precise instructions for how to reproduce it? Thanks.
Comment #6
Peacog CreditAttribution: Peacog as a volunteer commentedIt'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:
Comment #7
Peacog CreditAttribution: Peacog as a volunteer commentedComment #8
Peacog CreditAttribution: Peacog as a volunteer commentedThe 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:
Has taxonomy terms
filtertid
to something else, for examplemyterm
Checkboxes/Radio Buttons
filter typeMake this filter collapsible
option.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.
Comment #9
rlhawkThe latest patch fixes the issue. Thanks.
Comment #11
rlhawk