Skip to content

Instantly share code, notes, and snippets.

@boyron
boyron / drupal.views.filter.merge.php
Last active March 25, 2016 18:55
Drupal views: Merge contextual filter with exposed filters in query.
/**
* @file: MY_MODULE.views.inc
*
* Implementation of hook_views_query_alter().
* 1. Resolves conflict between contextual filter and regular filter (topic id, sub topic).
* Both refer to same database field, so merge them in one 'where' clause instead of two that Views comes up with.
* 2. By default, show all results from a topic and its sub-topics.
* [If a document is tagged with a sub-topic but not its parent topic, it was not shown in the default result.]
* @param view $view
* @param views_plugin_query_default $query