Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have some complex logic that I'd like to use to set the default values for the exposed date filter in my View. It's more complex than the current default options allow. So I tried using hook_form_alter() but that doesn't seem to work. Is there another place I can override the defaults when the exposed filter form is generated?
Thanks for your help.
Comments
Comment #1
Mat77 CreditAttribution: Mat77 commentedI did it like this :
Hope this can help
Mat
Comment #2
mstrelan CreditAttribution: mstrelan commentedThis won't help until the form is submitted. I think the OP wants the initial display of the view to be defaulted. I think something like hook_views_pre_build() will help but I haven't quite worked that one out.
Comment #3
mstrelan CreditAttribution: mstrelan commentedI was able to achieve this with the following code. It may not be the best way.
You would probably be better off altering
$view->display['default']->handler->options['filters']['date_filter']
though.Comment #4
fourmi4x CreditAttribution: fourmi4x commentedHi,
I tried to modify directly the view data with:
but nothing appears in the exposed filter... SHould I modify something else somewhere else?
Or is the pre_build hook simply not the right one for this?
Comment #5
purabdk CreditAttribution: purabdk commentedInstead of this you can use folloing code
Comment #6
liquidcms CreditAttribution: liquidcms commentedthanks @purabkharat, from your posting i figured out how to set a term ref field default value:
where _umd_get_current_term() is simply a custom function which returns the required/dynamic tid value.
Comment #7
DamienMcKennaWe're sorry but the D6 release of Date module is no longer being supported. You are encouraged to update to Drupal 7 or 8, or direct questions to Drupal Answers.