Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

Views Argument Substitutions

Security covered

Part of the Views ecosystem · 211 projects

View on drupal.org

INTRODUCTION

TL;DR: This module allows contextual filter arguments and exposed filters to be used as replacement tokens in other filters or table arguments.

What this means:

  • You can use Contextual Filters (even Null ones) to accept arbitrary input, and use that input as values in one or more Filters (example: searching for node titles containing some search keyword).
  • You can reuse an exposed Filter value as a value in other Filters (example: users can search for nodes based on title or tag using one field by exposing a node's "Title" field and using input in that field in an OR non-exposed filter on taxonomy terms).

Enhanced Contextual Filters

Contextual Filters allow a View to be filtered based on arguments passed via URL or other embedded method (e.g. the View Reference module), but contextual filters are inflexible compared with normal filters (contextual filters do not allow for "contains," "begins with," "ends with," etc.). With this module, you can use contextual filter values in filters.

Enhanced Filters

Exposing filters to allow users to search your site can be very powerful. Unfortunately, traditionally you need to expose a filter for every field that a user may want to search. With this module, you can expose a single filter, and reuse that input in many other (non-exposed) filters.

EXAMPLES

To search for a node by title containing some keywords:

  1. Create a new node-based ("Content") View: Go to admin/structure/views/add and under "Show", choose "Content".
  2. Add a "Global: Null" Contextual Filter (this step is required to allow the view to receive at least 1 argument).
  3. Add a "Content: Title" Filter: Under "Filter Criteria," click "Add." Choose "Content: Title," set the "Operator" to "Contains", and set the "Value" to "***!1***" (without the quotes). Click "Apply."
  4. Done! Any value passed as the first Contextual Filter argument will be used as the value for the Content: Title filter.

To search for nodes containing the same title as a specified node:

  1. Start by completing the example "to search for a node by title containing some keywords," as given above.
  2. Edit the "Global: Null" Contextual Filter: Enable "Specify validation criteria," and set "Validator" to "Content."
  3. Edit the "Content: Title (contains ***!1***)" filter: Change the "Value" from "***!1***" to "***%1***".
  4. Done! If you pass in a valid NID as the first Contextual Filter argument, its title will be used as the search value for the Content: Title filter.

Search node title, tag, author etc. with a single exposed search field

  1. Create a new node-based ("Content") View: Go to admin/structure/views/add and under "Show", choose "Content".
  2. Add "Content: Author" Relationship
  3. Add a "Content: Title" Filter: Under "Filter Criteria," click "Add." Choose "Content: Title," set the "Operator" to "Contains", and expose the filter. Click "Apply."
  4. Add "User: Name (raw)" filter, do not expose the filter, set Operator to "Contains" and Value to "***!title***".
  5. Done! Anything entered in the "Title" field will also search the username. You may want to change the "Title" label to "Search", and add taxonomy terms (also reusing the "***!title***" input), the options are limitless!

INSTALLATION

Activate the module, then administer a desired View. Add as many Contextual Filters as you need filter values (using "Global: Null", if appropriate), then insert corresponding tokens ("***!1***" for the first value, "***!2***" for the second, etc.) as filter values. Additionally, "***%1***" may be used to insert the title for the first argument (for example, if the argument is a node), and so on.

KNOWN ISSUES/SHORTCOMINGS

  1. The Search API module does not support any query substitutions (#2898924: Views query substitutions don't get substituted), so Search API integration is unsupported/unfeasible.
  2. The underlying hook_views_query_substitutions()
  3. only supports returning string values, so it is impossible to break an incoming string into a list. This means that filters using "Contains any word" or "Contains all words" will only "see" one word, even if it is separated by spaces. For "Contains any word," use a Regular Expression filter instead coupled with the REGEX replacement pattern.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Mar 2023
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
2.x-dev Dev Nov 14, 2023
1.x-dev Dev Mar 19, 2023