0

I have a custom entity "referral" which is available for views:

function mymodule_entity_info() {
  return array(
    'referral' => array(
      'label' => t('Referral'),
      'controller class' => 'EntityAPIController',
      'views controller class' => 'EntityDefaultViewsController',
      ...
    ),
  );
}

The mymodule_referral table has a field referred_at which is a timestamp (stored as an int); I'd like to add a filter on this field to my view. I've got it displaying and filtering correctly with hook_views_data_alter and views_handler_*_date, but I'd prefer popup date selectors.

I understand that the date_views submodule of date should do what I want, but I can't find proper documentation on how to use it.

function mymodule_views_data_alter(&$data) {
  ...
  $data['mymodule_referral']['referred_at']['filter'] = array(
    'real field' => 'referred_at',
    'handler' => 'date_views_filter_handler',
  );
}

doesn't seem to be sufficient, because it displays in the view edit page as

FILTER CRITERIA

    Referral: Referred_at (Missing date fields!) | Settings

If I open the settings there's a compulsory field

DATE FIELD(S) *
Select date field(s) to filter.

with no options to select.

The only reference I can find to the "Missing date fields!" error message talks about hook_date_api_fields, but that hook doesn't seem to exist in 7.

What configuration am I missing?

0

In addition to mapping 'handler' to 'date_views_filter_handler' you need to tell date_views that the field is a date:

function mymodule_views_data_alter(&$data) {
  ...
  $data['mymodule_referral']['referred_at']['filter'] = array(
    'handler' => 'date_views_filter_handler',
    'is date' => TRUE,
  );
}

In the filter settings for referred_at you will now see referred_at as an option for "DATE FIELD(S)", and if you select it then it will work as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.