Drupal 7 视图暴露的过滤器不起作用

Posted

技术标签:

【中文标题】Drupal 7 视图暴露的过滤器不起作用【英文标题】:Drupal 7 views exposed filter not working 【发布时间】:2015-08-18 11:25:55 【问题描述】:

我在 drupal 中使用视图 UI 创建了一个视图,然后我导出了代码并创建了一个自定义模块,该模块实现了 hook_views_default_views() 并进行了一些更改。该视图工作正常,我有很多过滤器。除 1 外的所有工作,一个类型:分组过滤器

    $handler->display->display_options['filters']['field_FIELDNAME_tid']['id'] = 'field_FIELDNAME_tid';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['table'] = 'field_data_field_FIELDNAME';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['field'] = 'field_FIELDNAME_tid';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_FIELDNAME_tid']['expose']['operator_id'] = 'field_FIELDNAME_tid_op';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['expose']['label'] = 'Field Label';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['expose']['operator'] = 'field_FIELDNAME_tid_op';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['expose']['identifier'] = 'field_FIELDNAME_tid';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['expose']['remember_roles'] = array(
    2 => '2',
    1 => 0,
    3 => 0,
);
$handler->display->display_options['filters']['field_FIELDNAME_tid']['is_grouped'] = TRUE;
$handler->display->display_options['filters']['field_FIELDNAME_tid']['group_info']['label'] = 'Field Label';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['group_info']['identifier'] = 'field_FIELDNAME_tid';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['group_info']['group_items'] = array(
    1 => array(
        'title' => 'Test',
        'operator' => 'or',
        'value' => array(
            2630 => '2630',
            2631 => '2631',
        ),
    ),
);
$handler->display->display_options['filters']['field_FIELDNAME_tid']['type'] = 'select';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['vocabulary'] = 'VOCABULARY_NAME';
$handler->display->display_options['filters']['field_FIELDNAME_tid']['hierarchy'] = 1;

视图正常工作,没有错误或通知,所有过滤器都显示并正常工作,除了这个。

【问题讨论】:

【参考方案1】:

几个小时后..我发现这是一个视图问题https://www.drupal.org/node/2224601

解决方案是只选中允许多选,保存视图,然后取消选中多选,这会将这一行放入视图中:

$handler->display->display_options['filters']['field_FIELDNAME_tid']['expose']['multiple'] = TRUE;

【讨论】:

以上是关于Drupal 7 视图暴露的过滤器不起作用的主要内容,如果未能解决你的问题,请参考以下文章

如果未定义第二个过滤器,则具有 2 个上下文过滤器的 Drupal 7 视图不起作用

Drupal 7 视图暴露的过滤器

如何主题化视图中暴露的过滤器项目 - drupal 6

视图“搜索词”暴露的过滤器在 PROD 中不起作用,但在本地起作用

Drupal 7 从 mysql 数据库恢复不起作用

干净的网址在 Drupal 7 中不起作用 [关闭]