Add proper validation constraints to the `value` property of date fields

Created on 17 June 2025, 7 days ago

Problem/Motivation

This is the bigger brother of πŸ› There is no config schema for the `value` property of `datetime` fields Active . See that issue for background info (tl;dr: you can't store a default value for a date field, regardless of validity, because the value property isn't defined by config schema).

That issue proposes a quick-fix of marking the value property as ignored, which will allow any ol' value to be stored in there (i.e., the status quo) without running afoul of config schema. In this issue, let's add a proper set of validation constraints to the default value, ensuring that we're covering all the various shapes that a date field's value could take, and mark the field.value.datetime schema type as fully validatable.

In Slack, @catch shared with me a screenshot of what Wim felt might make some reasonable constraints for a date field value:

We could maybe start with those. And tests, of course.

User interface changes

Shouldn't affect the UI.

API changes

None anticipated.

Data model changes

Date fields' default values will be fully validatable, and therefore must conform to the constraints we come up with here.

Release notes snippet

TBD.

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

datetime.module

Created by

πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @phenaproxima
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Date type relative accepts the value, see the handleDefaultValue method

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Per \Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList::processDefaultValue there is no value key, you pass default_date_type of relative and

Production build 0.71.5 2024