Drupal Exposed Views Filter custom date

2019-05-07 18:57发布

问题:

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