繁体   English   中英

Drupal 7查看上下文过滤器或逻辑

[英]Drupal 7 Views contextual filters OR logic

上下文过滤器应用于AND逻辑。 有没有办法在OR逻辑中有两个或更多的上下文过滤器?

在视图7.x-3.5中,使用UI可能无法实现。

假设您的模块名称是my_module

将以下内容添加到my_module.module文件中

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

以下是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');
  }
}
?>

资料来源: http//drupal.org/node/1451218#comment-6136692

而在早期版本的视图中,上下文过滤器的AND / OR选项将由视图中第一组静态过滤器的AND / OR选项决定。

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.

这是一个允许“将参数传递给普通过滤器[UI]”的补丁“ https://drupal.org/node/357082

如果你坚持只有一个UI选项,那么这个模块就可以了。 我已经对它进行了测试,虽然似乎确实存在问题,但它会定期维护。 当我将它安装在我的自定义Drupal发行版上时,它似乎没有破坏任何东西(虽然我确实修改了一些代码以消除我的自定义代码出现一些问题的可能性)。

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

此外,如果您希望进一步隔离此模块的行为(以便它仅适用于特定视图或适用于特定内容类型的视图),则代码本身很容易导出到您自己的模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM