Drupal 公开视图过滤器自定义日期 [英] Drupal Exposed Views Filter custom date
问题描述
我有一个日期过滤器,在我的视图中公开.我想让界面更加用户友好并收紧它的外观.我想从以下选项中进行选择,而不是选择日期.
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.
- 最后一天
- 上周
- 去年
- 全部
这将过滤日期字段.这可能吗?你会怎么做?
This would then filter on the date field. Is this possible? How would you go about doing this?
推荐答案
正确的做法是使用 hook_form_alter
:
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
是一个描述表单的数组,使用 Drupal 表单 API.你可以使用 dpm
来检查这个数组://drupal.org/project/devel" rel="noreferrer">开发 模块.
$form
is an array describing the form, using Drupal Form API. You can inspect this array using dpm
from the Devel module.
这篇关于Drupal 公开视图过滤器自定义日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!