Form alter强制暴露视图过滤器为fllow过滤器选项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Form alter强制暴露视图过滤器为fllow过滤器选项相关的知识,希望对你有一定的参考价值。

callback in a form alter to enforce an exposed filter to use only the options set in filter. Works for selectlists only.
  1. /**
  2.  * Form alter hook Callbacks and helpers
  3.  */
  4. function _mymodule_formalter_exported_filter(&$form) {
  5. $filter_id = 'workflow_node.sid'; //set this to the id of the filter. use print_r($form['view'][#value']->filter) to find the ID
  6.  
  7. foreach($form['view']['#value']->filter as $filter) {
  8. if ($filter['field'] == $filter_id) {
  9. $only_these = $filter['value'];
  10. break;
  11. }
  12. }
  13.  
  14. foreach ($form['filter0']['#options'] as $key => $option) {
  15. if (in_array($key, $only_these)) {
  16. $options[$key] = $option;
  17. }
  18. }
  19. $form['filter0']['#options'] = $options;
  20.  
  21. if(is_array($form['filter0']['#default_value'])) {
  22. $form['filter0']['#default_value'] = 40; //or any other value.
  23. }
  24. }

以上是关于Form alter强制暴露视图过滤器为fllow过滤器选项的主要内容,如果未能解决你的问题,请参考以下文章

如何在查看日期暴露过滤器下拉列表中删除“-Year”选项?

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

Drupal 公开视图过滤器自定义日期

暴露的过滤器:无与所有结果

Drupal 7 视图暴露的过滤器

Drupal 视图和暴露的过滤器下拉菜单