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.
Situation:
You add a filter twice (so you have instances of the same filter). Then you expose them.
Problem:
_views_view_build_filters() iterates over $view->filter
then tries to match the correct exposed instance by looping over $view->exposed_filter
and checking the condition: if ($filter['id'] == $expose['id'])
. It works if the filter has only one exposed instance. However, if there are more, the first exposed instance of the filter is going to match everytime.
Proposed solution:
Patch attached
Comment | File | Size | Author |
---|---|---|---|
#5 | views_filter_twice.view_.txt | 2.03 KB | AmrMostafa |
views_filters_build_used_check.patch | 470 bytes | AmrMostafa | |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedOk, I must congratulate you on a 1 line fix that had simply never occurred to me that fixes a major limitation of Views. I was about to won't fix the issue and then I actually looked at the patch.
Comment #2
abu3abdalla CreditAttribution: abu3abdalla commentedi will try it
Comment #3
Kripsy CreditAttribution: Kripsy commentedWould this fix the problem of using a taxonomy as an argument and exposed filter?
Comment #4
trofimchouk CreditAttribution: trofimchouk commentedPatch needs fix.
In case of two optional filters (for the same field) the second one does not work.
So should change
!isset($view->used_filters['filter'. $count])
to
!isset($view->used_filters['op'. $count])
Comment #5
AmrMostafa CreditAttribution: AmrMostafa commentedI cannot reproduce #4
Attached my test view export. Here is a summary:
Comment #6
trofimchouk CreditAttribution: trofimchouk commentedOh.. sorry, I haven't mention that these filters are the CCK-Integer filters.
So to reproduce you should:
- have a Content type with CCK-Integer field
- create several nodes (with values of 2000, 3000 and 4000)
- create view with 2 filters for these fields (1st - "more", 2nd - "less") - So you get a kind of range filter.
- try to filter with "more than 2500" and "less than 3500"
- you should get all the nodes with field value more than 2500 but not less than 3500
Comment #7
Terran-2 CreditAttribution: Terran-2 commentedI think this patch is meant to fix the problem I'm having, but after changing line 89 of views_query.inc from "if ($filter['id'] == $expose['id']) {" to "if ($filter['id'] == $expose['id'] && !isset($view->used_filters['filter'. $count])) {" as suggested by the original patch and to "if ($filter['id'] == $expose['id'] && !isset($view->used_filters['op'. $count])" as suggested by lancelot (#4) it doesn't seem to.
What I'm trying to do:
Filter my view using minimum and maximum values for a few fields (price, and home square footage). This works fine as long as I DON'T lock the operator (is greater than, etc.). If I lock the operator the view returns no results
What seems to be happening:
Views is taking the operator from the first instance of the field and using it in both filters. This doesn't break things when the operator can be changed manually, but when the operator is locked it breaks.
Should this patch fix this problem? What might I be doing wrong?
Thanks!
Comment #8
askibinski CreditAttribution: askibinski commentedI also applied the original patch, which did not work for 2 exposed filters on a cck integer field. (same usecase as lancelot at #6). I couldn't get any results back from great then (or equal) and smaller than or equal queries.
Then I also tried the modification at #4. Also no results.
Using Views 1.6.
Comment #9
esmerel CreditAttribution: esmerel commentedAt this time, only security fixes will be made to the 5.x version of Views.