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.
When a custom entity is created, and one of the fields is a datetime FieldType, views filters are not treating this field like a datetime field, but, instead, like a string. Timestamp Fieldtypes on the other hand are presented with the correct filter options.
Comments
Comment #2
LendudeYes, it does default to a string. I think the underlying reason is this:
Datetime support comes from the datetime module, so if you want your entity to use that, add a dependency to datetime and override any defaults for your entity in an extension of
\Drupal\views\EntityViewsData
.The Views 'date' filter only works for timestamps (hence your timestamp fields work out-of-the-box), so just setting the filter plugin_id to 'date' won't help either.
So this works as designed I think.
Comment #3
BeakerboyThat makes no sense...why even include this field type when a timestamp does everything and more?
Comment #4
rlmumfordI'm not sure why this is closed as 'works as designed' when there's just been a big issue about datetime range fields for exactly the same reason.
https://www.drupal.org/node/2786577
Comment #5
Nchase CreditAttribution: Nchase as a volunteer commentedrlmumford, I don't understand it either. The whole date filed is kind of a problematic thing. The entire feature set from Drupal 7 was completeley cut down. There is now date and date range and both can't be filtered agains relative values in views. The end date of a date rang can't be filtered agains in views.
Comment #6
justkristin CreditAttribution: justkristin commentedAgreed. There is no going back to 7 at this point, but from a date/time/calendar perspective, D8 is severely hobbled at best. This should not be closed, or, if it indeed "works as designed", an explanation of that would be nice.
Comment #7
dpiComment #9
mandclu CreditAttribution: mandclu commentedI saw this as a significant issue as well, to I've created a project to provide a date range field based on timestamps at https://www.drupal.org/sandbox/surgemartin/3045703
There's also some work there to provide a time/date interface that's closer to popular calendar apps, in the sense that you can set a default duration and it will auto populate the end based on the start.
Once I get the views integration sorted out I will move it to beta.
Comment #17
Ada Hernandez CreditAttribution: Ada Hernandez at MTech, LLC commentedI faced this issue with my custom entity and views filter, adding field_name as here is suggested and
the views type filter to handle the date in my getViewsData() method and that works.