Can't set default for DateTimeItem

Created on 17 June 2015, over 10 years ago
Updated 6 September 2025, 16 days ago

My entity has a datetime field depending on the datetime module.
that means in $entity->precreate I'm setting a default time:
$values['mydatetimefield'] = 'some value'//I think DrupalDateTime::createFromArray(['year'=> 1980, 'month'=> 8, 'day' => 8]);
This value however is not set in $items->setValue() because in FieldItembase::setValue() it looks for the first property name $keys[0], which is 'value' (as defined in DateTimeItem::propertyDefinitions).
However in DateTimeWidgetBase::formElement, it expects the other property, 'date' to be populated.
Consequently, $items->getValue() isEmpty, because $values['date'] is not set;

Its a bit of a mess but that's the best I can report at the moment...

🐛 Bug report
Status

Closed: outdated

Version

11.0 🔥

Component

datetime.module

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024