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.
Problem/Motivation
Adding a DateItem
to your entity currently does not work at all.
Steps to reproduce
- Add the following to
Node::baseFieldDefinitions()
:
$fields['broken_date'] = FieldDefinition::create('date');
- Clear caches
- Go to
node/add/article
Expected result:
You are able to edit a node.
Actual result:
InvalidArgumentException: Invalid data type date has been given. in Drupal\Core\TypedData\TypedDataManager->createInstance() (line 91 of core/lib/Drupal/Core/TypedData/TypedDataManager.php)
Details
The exception message is right: There is no @DataType
plugin with the id date
.
Proposed resolution
Remaining tasks
User interface changes
None.
API changes
Comment | File | Size | Author |
---|---|---|---|
#6 | kill-dateitem-2150511-56.patch | 1.4 KB | Berdir |
#3 | 2239241-3-date-field.patch | 685 bytes | mr.baileys |
Comments
Comment #1
tstoecklerNote, because I just realized this might be confusing:
There is a
@FieldType
plugin with IDdate
, so the example code is valid. SeeDateItem
.DateItem
itself uses the typed data plugin with IDdate
for itsvalue
property. That is the one that doesn't exist which is why this is broken.Comment #2
tstoecklerRaising to major. This is really, really bad. It can't be triggered from the UI so not critical, but certainly major.
Comment #3
mr.baileysCould the fix be as simple as changing DateItem to use the DateTimeIso8601 typed data definition?
Comment #4
BerdirYeah, looks like this was never updated when we renamed that.
Another question is if this should be dropped/merged with the datetime module field type.
Comment #5
BerdirAs suggested in #2150511: [meta] Deduplicate the set of available field types, I think we should simply drop this in favor of DateTimeItem from datetime.module.
Comment #6
BerdirComment #7
swentel CreditAttribution: swentel commentedComment #8
yched CreditAttribution: yched commentedYep, +1.
AFAICT through git log tracking, DateItem was introduced in the very original "Entity Property API" patch in #1696640: Implement API to unify entity properties and fields as one of the available "EntityNG field types", but was never actually used for anything...
Comment #9
alexpottCommitted 769d611 and pushed to 8.x. Thanks!