Drupal Exposed Views Filter custom date

2019-05-07 18:59发布

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?

2条回答
男人必须洒脱
2楼-- · 2019-05-07 19:28

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.

查看更多
爷、活的狠高调
3楼-- · 2019-05-07 19:29

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

查看更多
登录 后发表回答