DrupalEasy: Reintroducing Drupal core's Views "Combine fields filter"

Image removed.

I was recently reminded of a Drupal core feature that I hadn't used in a long time - and was pleasantly surprised at how useful it is.

The Combine fields filter Views filter allows a site-builder to quickly and easily set up an exposed filter that searches multiple fields for a given search term. Think of it as a way to combine multiple exposed search filters into a single search box.

Setting it up is quite easy - just include all the fields that you want to search in the Fields section, marking them with Exclude from display as necessary (Unfortunately, Combine fields filter doesn't work with view modes.)

Then, add and expose a Combine fields filter to the view, and configure it to use all the fields you want searchable in the Choose fields to combine for filtering section of the filter's configuration:

Image removed.

 

I created a simple example of a Movie content type with example fields including Title, Image, Plot summary, Spoilers, Year of release, Short description, Taglines, and Trivia. I added all of these fields to the Fields configuration of the view - with all of them hidden except for Title and Image.

Next, I added a Combine fields filter as described above, selecting all of the fields to be combined for filtering. Finally, I added a few sample Movie nodes.

To test things out, I searched for terms that were added as part of the various Movie content type fields (but purposely not words in the Title fields). The results were exactly what I was expecting!

In the first example, the word biff appears in the Plot summary field for Back to the Future

In the first example, the word biff appears in the Plot summary field for Back to the FutureImage removed.Next, the word saga appears in the Short description field of The Last Jedi.Image removed.The number 1985 appears in the Year of release field of Back to the Future.Image removed.Finally, the words Michael Caine appear in the Trivia field of The Dark KnightImage removed.


There are a few caveats when using Combine fields filter with one of the more impactful being that when utilizing a multivalued field (as the Trivia and Taglines fields are in the previous example), the Multiple field settings configuration cannot utilize the Display all values in the same row option. Fortunately, these fields are usually excluded (hidden) from search views like this. 

Image removed.
PubDate

Tags