Drupal暴露视图过滤自定义日期 [英] Drupal Exposed Views Filter custom date
问题描述
- 最后一天
- 上周
- 最后一年
- 全部
然后,这将过滤日期字段。这可能吗?你会如何去做这个?
正确的方法是使用< 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屋!