Facet behaviour on exposed view filters

Having recently tested the Views Reference Filter module, I realised that it allows you to get faceted behaviour on exposed view filters. The module lacks documentation which is being developed in a issue Drupal.org so it is difficult to understand where it acts.

I use the term "facet behaviour" here in the sense that it is possible to refine filter options based on the choice of other filters so that a result can always be offered.

Principle

It's based on the Entity reference module, which provides an entityreference field type that can refer to any type of entity. But the Entity reference module also provides a view display (view display) "entityreference".

Views Reference Filter adds a new type of view filter to all reference fields (entityreference, term reference, etc.). With this new filter, you can choose an entityreference view display whose results will be the possible values of the exposed filter. And it's possible to pass arguments AND view filter values as arguments to the entityreference display.

So yes, you need to be comfortable with the notions of views and entityreference, particularly "relationships" and "contextual filters" to understand what's going on.

Example

On the screenshots, you can see an example.

Here are the view configurations just in case:

A basic content type with 3 "term reference" fields pointing to 3 distinct vocabularies.

I'm using a basic context to place a view block on vocabulary 1 taxonomy term pages.

In the view block, there are:

  • a contextual filter on the vocabulary 1 field so that it filters on the vocabulary 1 term we are currently viewing.
  • 2 exposed filters using 2 entityreferences displays (these displays are symmetrical so I'll only detail one each time), I pass them as arguments:
    • the argument of the "!1" block which corresponds to the tid of the taxonomy term currently being looked at, but I have the impression that the argument doesn't go down well so in the entityreference displays I default to the tid from the URL.
    • the value of the other exposed filter "[field_vocabulary_3_tid_entityreference_filter]"

In entityreference displays, important clarification, their base table must be that of the entity type used in the filter, here in my exposed filters are taxonomy terms so I must make a view on taxonomy terms:

  • as we start from taxonomy terms, we need a relation to nodes using the display vocabulary
  • with this relation we can get the terms from the other vocabularies
  • Then we need to add 2 contextual filters:
    • one for the vocabulary term consulted
    • another for the vocabulary term chosen in the other exposed filter

Whether in the block view or the entityreference displays, you need to use the "distinct" option or even "pure distinct" given the number of joins. As this is a block view, the filters will not appear if you use the ajax option.

Conclusion

I have in a previous test used a view display of type EVA, ajax level was average.

The best thing would be to be able to add a hierarchical select type widget and there that would meet a need that many customers have I have the impression.

Comments

Add new comment