我在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;
视图有效并且没有错误或通知,所有过滤器都显示并且工作正常,除了这个。
答案 0 :(得分:0)
几个小时后......我发现这是一个视图问题https://www.drupal.org/node/2224601
解决方法是只检查允许多个选择,保存视图,然后取消选中多个选项,这会将此行放入视图中:
$handler->display->display_options['filters']['field_FIELDNAME_tid']['expose']['multiple'] = TRUE;