I have a custom entity with a date field in it. I have spent a lot of time reviewing several posts related to this issue:

https://www.drupal.org/project/drupal/issues/2489476 https://www.drupal.org/project/drupal/issues/2648950

https://www.drupal.org/node/2337515

I have not been able to resolve the issue in my project. I have determined that I needed to add some code in my views.inc file such as below

function timeoff_views_data_alter(array &$data) {
  $data['time_off_day']['timeoffdate']['filter']['id'] = 'datetime';
}

I have not been able to get the datepicker to work, nor can I get the debugger to stop in the view.inc routine. I have better-exposed filters and data popup installed and the date pickers are working on all the other date fields in the site. My custom entity has a created date and then a timeoffdate, date picker in the view works on the created date and not the timeoffdate. But in the add/edit they are both working fine.

I also want to note that the module is timeoff wiht multiple custom entities. The entity that I am specifically working on is time_off_day.

Thanks for any help that you can provide.

UPDATE

I have gotten the following code to work in the project

$data['time_off_day_field_data']['timeoffdate']['filter']['id'] = 'datetime';
  $data['time_off_day_field_data']['timeoffdate']['filter']['title'] = 'Time Off Day Test';
  $data['time_off_day_field_data']['timeoffdate']['filter']['field_name'] = 'timeoffdate';

I am getting this error on the page when I go to the view

The website encountered an unexpected error. Please try again later. Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::get() in Drupal\datetime\Plugin\views\filter\Date->buildExposedForm() (line 190 of core/modules/datetime/src/Plugin/views/filter/Date.php).

  • You can't get the debugger to stop because views_data is cached. In the linked issue there seems to be a solution containing much more views data than you've posted, see #13. Did you try this? – 4k4 Dec 3 at 7:36
  • @4k4 Thanks for the suggestion. I have tried #13 before, I just put the code back into that area again. I can't get anything to debug or stop into the code. I placed the code in the auto-generated file TimeOffDayViewsData.php in the getViewsData() function. I can't get the debugger to stop in that file at all. – Robert Fulcher Dec 3 at 11:02
  • You might have good reasons to use a base field, but you know that a date field configured in UI works? – 4k4 Dec 3 at 11:07
  • Yeah I know the date field configured in UI works, this is a custom entity and was created and has been used for some time. Now we need to add a view where they want to filter by the date. Can't go back now and change it. – Robert Fulcher Dec 3 at 11:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.