5

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

4

3 回答 3

7

在视图 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 选项将由视图中的第一组静态过滤器的选项决定。

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.
于 2012-11-23T16:36:41.653 回答
0

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

于 2014-01-18T02:14:43.943 回答
0

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

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

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

于 2016-06-20T20:48:30.173 回答