Drupal Exposed Views Filter custom date

谁说胖子不能爱 提交于 2019-12-07 08:29:03

问题


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?


回答1:


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.




回答2:


It is possbile, but you will need to write your own module for that.

That module would use the method called "Form Alter" to change the form. Try starting here http://drupal.org/node/157253



来源:https://stackoverflow.com/questions/3049334/drupal-exposed-views-filter-custom-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!