Views: Use default value from URL for contextual filter, THEN show all if default value empty? Short version, general question: You want to pipe in a 'Default value', specifying a URL argument, to a contextual filter in Views 3. You also want all results (the full unfiltered view) to be displayed if this argument in the URL is empty. However, "Default value" and "Display all rows if empty" settings in Views contextual filters are mutually exclusive, and the default if nothing is passed to the filter is to show nothing. 

How can you achieve this?



Full version with case specifics: I'm using a Context View with a contextual filter on a Search API index to search based on search terms in a URL: path like "/search/my%20search%20terms, loaded into a Page Manager panels page as a page context so that bits of the view can be dispersed across the page regions. Pretty standard use of Search API Views.

Since you can't specify what arguments or contexts to pass to a context view in Page Manager / Panels when loaded as contexts in the Contexts form (unlike block views etc, loaded as content, where you can explicitly pass in arguments or contexts), I need to tell it which URL argument it will find the search terms in using the 'Provide default' options under Contextual Filters in the Views settings for the view. 

This works, but has an unintended side effect - if someone goes to the search page without any terms (navigates to /search or submits an empty search box), they get nothing. I'd like this path to show the full unfiltered view (it's full of search facets and such so just navigating to it without search terms works like a drill-down browse/advanced search page). 

If this was a block or loaded as content in panels/page manager, I could set "If no filter value is provided" to show all rows and use panels/page manager to pass in the current URL argument. But, in Views UI, default values and 'Show all' are mutually exclusive.

So, how to use a default value for a contextual filter, then show all if that default value isn't present or is empty?
Even faster: 
PHP is not even needed to just display all values... 


Under "When the filter value IS available or a default is provided
Tick "Specify validation criteria" Choose 'Basic validation'
Under "Action to take if filter value does not validate", choose "Display all values"