Drupal暴露视图过滤自定义日期 [英] Drupal Exposed Views Filter custom date

查看:130
本文介绍了Drupal暴露视图过滤自定义日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期过滤器,我已经暴露在我的看法。我想使界面更加用户友好,并收紧它的外观。而不是选择日期,我想从以下选项中选择。




  • 最后一天

  • 上周

  • 最后一年

  • 全部



然后,这将过滤日期字段。这可能吗?你会如何去做这个?

解决方案

正确的方法是使用< a href =http://api.drupal.org/api/function/hook_form_alter =noreferrer> hook_form_alter

 函数YOURMODULE_form_alter(& $ form,$ form_state,$ form_id){
if($ form_id =='views_exposed_form'){
$ view =& $ form_state ['view'];
$ display =& $ form_state ['display'];
if($ view-> name =='YOURVIEWNAME'&& $ display-> id =='YOURDISPLAYID'){
//更改$ form here,use dpm($ form )来检查它。
}
}
}

$ form 是一个描述表单的数组,使用Drupal 表单API 。您可以使用 dpm 从<一个href =http://drupal.org/project/devel =noreferrer> Devel 模块。


I have a date filter that I have exposed on my view. I want to make the interface more user friendly and tighten up the look of it. Instead of selecting a date I would like to select from the following options.

  • The last day
  • The last week
  • The last year
  • All

This would then filter on the date field. Is this possible? How would you go about doing this?

解决方案

The proper way to do it is to alter the form in a custom module using hook_form_alter:

function YOURMODULE_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    $view = &$form_state['view'];
    $display = &$form_state['display'];
    if ($view->name == 'YOURVIEWNAME' && $display->id == 'YOURDISPLAYID') {
      //Alter $form here, use dpm($form) to inspect it.
    }
  }
}

$form is an array describing the form, using Drupal Form API. You can inspect this array using dpm from the Devel module.

这篇关于Drupal暴露视图过滤自定义日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆