简体   繁体   English

使用层次选择时,如何在Drupal视图中更改暴露滤镜的默认值(-Any-)?

[英]How to change the default value (-Any-) of an exposed filter in Drupal Views, when using Hierarchical Select?

I've made a view with an exposed filter. 我已经使用裸露的滤镜进行了查看。 This filter is taxonomy based, and I'm using Hierarchical Select as the widget because this taxonomy is deeply nested. 该过滤器基于分类法,我将Hierarchical Select用作窗口小部件,因为此分类法是深层嵌套的。

This question is greatly similar to: How to change the label of the default value (-Any-) of an exposed filter in Drupal Views? 这个问题非常类似于: 如何在Drupal视图中更改暴露过滤器的默认值(-Any-)的标签?

However, the poster of that question was not using HS, and so I cannot use the answers there, specifically this one: https://stackoverflow.com/a/5975294/443219 但是,该问题的发布者未使用HS,因此我无法在此处使用答案,尤其是以下答案: https : //stackoverflow.com/a/5975294/443219

Where exactly should I place the '#options' key in the $form array when using hook_form_alter, to make this work? 使用hook_form_alter时,我应该在$ form数组中的哪个位置放置'#options'键,以完成这项工作? I've tried pasting the relevant line of code blindly in different places throughout the array, but I believe HS works a tad different to FAPI... 我试图在整个数组的不同位置盲目地粘贴相关的代码行,但是我相信HS的工作方式与FAPI有点不同...

You can use following code any drupal module. 您可以在任何drupal模块中使用以下代码。 this will work. 这将起作用。

/**
 * hook_views_pre_view
 * @param type $view
 * @param type $display_id
 * @param type $args
 */
function MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) {
  if ($view->name == 'VIEW_NAME') {
    $filters = $view->display_handler->get_option('filters');    
    $view->display_handler->override_option('filters', $filters);
  }
}



/**
 * hook__views_pre_build
 * @param type $view
 * @return type
 */
function MODULE_NAME_views_pre_build($view) { 
  if ($view->name=='VIEW_NAME') {    
    $view->display['page']->handler->handlers['filter']['filter_field']->value['value'] = 8;
    return $view;
  }     
}

I have a horrible answer to this. 我对此有一个可怕的答案。

I changed line 402 in sites/all/modules/hierarchical_select/hs_taxonomy_views.module from: 我从以下位置更改了site / all / modules / hierarchical_select / hs_taxonomy_views.module中的402行:

$any_label = variable_get('views_exposed_filter_any_label', 'old_any') === 'old_any' ? '<'. t('Any') .'>' : '- '. t('Any') .' -';

to

$any_label = variable_get('views_exposed_filter_any_label', 'old_any') === 'old_any' ? 'Worldwide' : '- '. t('Any') .' -';

This works because: in this site, I need the filter on only view - and nowhere else. 之所以有效,是因为:在此站点中,我只需要在视图上过滤该过滤器,而在其他地方则不需要。

This can never be a general solution because: 这永远不是一个通用的解决方案,因为:

  1. The unholy sin of hacking the core of a module will haunt me forever because I cannot ever use drush to update this module again. 破解模块核心的邪恶罪恶永远困扰着我,因为我再也无法使用drush来更新该模块。
  2. If I ever make another view in this site, and decide to have a hs taxonomy exposed filter, it's "Any" option will be displayed as "Worldwide", even if there is no such context: weird. 如果我曾经在此站点上发表过另一种观点,并决定使用hs分类标准公开过滤器,即使没有这样的上下文,它的“ Any”选项也将显示为“ Worldwide”:很奇怪。

I would greatly appreciate if anyone can point me in a direction that will allow me to solve this cleanly. 如果有人能指出我的方向,让我彻底解决这个问题,我将不胜感激。 But I'm going with my hack for now. 但是我现在要进行破解。

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

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