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...
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 2507775-10-TEST-ONLY.patch | 3.27 KB | jhedstrom |
Comments
Comment #1
matslats commentedPS I've also tried setting the basefield property like this:
Then
Comment #2
handkerchiefi can't set a default value like this:
Is this a bug or am i doing it wrong?
Comment #4
jhedstromDoes the fix over in #2778083: Default value for Date-Only fields is broken when UTC date is different than user current date address this?
Comment #7
hatuhay commentedAny news on this one.
I am trying:
and
No success
Comment #10
jhedstromThis adds a passing test. It doesn't try to set the value to a datetime object as posted above, but works. This test fails if an object is used instead of a string, as there is nothing in the datetime field to translate that back before it attempts to save to the db.
So there may be an issue here in that default values cannot be set as
DrupalDateTimeobjects, so we could either resolve that somehow, or update the documentation...Comment #15
sivaji_ganesh_jojodae commentedI'm trying to add created & changed columns to Commerce Store entity. This issue has been a bummer. Trying to run sql update query to workaround this.
Comment #21
quietone commentedI think is outdated as of #2830094: Deprecate and remove usages of datetime_date_default_time().. That issue also added tests and documentation.
If I am wrong, re-open the issue.