Adding a Date Filter to Views When Using Custom Fields

I recently exposed some custom database tables to views using hook_views_data() which as usual was a pleasant experience, until I wanted to use the date filter that the Date module provides. This isn't creating a filter on your field, it's the field in the list that looks like Date (node). The word "node" in brackets is referring to the base table that will be used for the date filter, this allows you to compare multiple dates from the same table. So the hook you're looking for: hook_date_views_extra_tables(). It took me about 2hrs to find out so I hope this saves someone else sometime.

An Example

/*
 * Implements hook_date_views_extra_tables().
 */
function MODULE_date_views_extra_tables() {
  return array($base_table="base_table", $entity_name="entity_name");
}

Comments

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.