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

Beakerboy created an issue. See original summary.

Lendude’s picture

Priority: Major » Normal
Status: Active » Closed (works as designed)
Issue tags: +date

Yes, 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.

Beakerboy’s picture

That makes no sense...why even include this field type when a timestamp does everything and more?

rlmumford’s picture

Version: 8.2.5 » 8.6.0-alpha1
Status: Closed (works as designed) » Needs work
Related issues: +#2786577: The Views integration Datetime Range fields should extend the views integration for regular Datetime fields

I'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

Nchase’s picture

rlmumford, 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.

justkristin’s picture

Agreed. 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.

dpi’s picture

Version: 8.6.0-alpha1 » 8.7.x-dev

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mandclu’s picture

I 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.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Ada Hernandez’s picture

I 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.

$data['my_entity']['date_field']['filter'] = [
      'id' => 'datetime',
      'field_name' => 'date_field',
    ];

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.