Normally, when a Views field has been assigned both an exposed filter and a contextual filter, then both filters get applied to the View's results set -- always. This is not configurable behaviour. It's hard-coded.
As a consequence, contradictory search clauses easily occur, causing a counter-intuitive user experience with some White Screens of Disillusionment. Since the contextual filter sets the "bounds" for the page, any filtering by the visitor through the exposed filter on that page can only narrow down the results set, not broaden it. In other words the exposed filter appears not to be working properly.
This small module allows you to have a contextual filter argument apply only when there is no corresponding regular (exposed) filter value present.
This is most common on initial page load. After that the contextual filters will silently retreat and let the exposed filter values as selected by the visitor do their thing without interfering.
This means that you can take advantage of friendly URLs using contextual arguments instead of ugly and verbose query parameters. Put the URLs anywhere on your site, in emails and in newsletters to take visitors to tailored Views pages. Having arrived there, visitors may then further filter these pages to their heart's content using the View's regular filters you exposed.
And they won't experience any odd behaviour.
Hands on: the problem and the solution in 60 seconds
You can do this on your own test site or you can click Try out a demonstration and press "Launch sandbox" to simplytest the latest version of Views Filter Harmonizer live online.
Let's go through a simple scenario.
- Login as administrator
- Create two pieces of content of type Article. For the first, type the tag name "blue", for the other enter the tag "red".
We'll demonstrate Views' confusing default behaviour first, using a View that is already on your system.
- Check the Views UI submodule is enabled while Views Filter Harmonizer isn't yet.
- At admin/structure/views, enable the canned View named Taxonomy term and edit it.
- Under Filter Criteria click Add and tick the box Content: Has taxonomy terms (with depth). This is the counterpart to the contextual filter that already exists on this View. Click Apply
- On the next panel, tick the Tags vocabulary, Dropdown and Apply.
- Then tick Expose this filter to visitors and press Is one of. Apply and Save the View.
- Visit /taxonomy/term/1, where we assume that 1 is the id of the "blue" term (Article tag)
- You'll see your "blue" article as expected.
- Switch the colour drop-down to "red" and press Apply.
- Duh? No output? That's right. That's default Views behaviour for you. You are filtering on all content that is both "blue" (via the contextual filter) and "red" (via the exposed filter). Confusing and not what we want is it?
So now, for some much needed relief, enable Views Filter Harmonizer.
- If you do not wish to see any informational/debug messages, visit People > Permissions and untick at the bottom of the page the box titled View info/debug messages.
- Revisit the Views UI and after clicking the regular filter name under Filter Criteria tick the box Override the companion contextual filter.
- Revisit /taxonomy/term/1, viewing the "blue" article as before. Notice also that the drop-down has been updated to reflect the contextual filter value.
- Switch the colour drop-down to "red" and voila: we see "red", as expected. And.... if you tick the extra configuration option, the browser address bar will be updated to reflect the new filter selection, without an extra reload of the page :-)
- Switch to "- Any -" and see both red and blue, as expected.
Refer to the README for notes on the use of this module with Views displayed in blocks.