Drupal 7 Context Filter Views OR logic

Context filters are applied in AND logic. Is there a way to have two or more context filters in OR logic?

+4
source share
3 answers

In 7.x-3.5 views, this may not be possible using the user interface.

Suppose your module name is my_module

Add the following to your my_module.module file:

 <?php function my_moudle_views_api() { return array( 'api' => 3, ); } ?> 

and

following in my_module.views.inc

 <?php function eb_mine_views_query_alter(&$view, &$query) { if ($view->name == 'statuser') { dsm($query, 'before'); $query->where[0]['type'] = 'OR'; dsm($query, 'after'); } } ?> 

Source: http://drupal.org/node/1451218#comment-6136692

Whereas in an earlier version of the views, the AND / OR parameter of the context filter will be determined by the parameter of the first group of static filters in the view.

 Grouping of contextual filters Even though contextual filters do not appear in the "and/or" user interface for sorting and grouping regular filters, contextual filters are always added to the first group of filters. Thus the order of the groups can cause the contextual filter to have entirely different effects on the results of a view that has contextual filters. Even though differences might not be apparent through the user interface. Multiple contextual filters are therefore always in the same "and/or" group of filters, and can not be placed in different groups. There is an effort to add this feature. 
+6
source

This is a patch that allows you to "pass an argument to a regular filter [UI]" https://drupal.org/node/357082

0
source

If you insist on having a user interface option, then this module will do the trick. I tested it and although it seems that there is potential for problems, it is regularly maintained. It did not seem to break anything when I installed it on my own Drupal distribution (although I modified the code a bit to eliminate some problems with my custom code).

https://www.drupal.org/project/views_contextual_filters_or

In addition, the code itself can be easily exported to its own module if you want to further isolate the behavior of this module (so that it applies only to certain views or views that relate to certain types of content).

0
source

Source: https://habr.com/ru/post/1447978/


All Articles