I've made a base field on a custom entity with type "datetime" using "datetime_default" for the form display. It's displaying as only a date picker, with no time component, whereas I want it to look like this:
If I create a field in the GUI I can select between "date only" or "date and time". (The image above is the result of picking "date and time"). But I can't work out how to do this programmatically. I've tried creating fields of both types and exporting the config, but there is no difference between them, which is a mystery.
I suspect I need to put something other than "datetime_default" but I can't find any documentation on how to programmatically refer to the various date and time widgets.
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['activity_date_time'] = BaseFieldDefinition::create('datetime')
->setLabel(t('Date and time'))
->setDescription('')
->setRevisionable(TRUE)
->setRequired(TRUE)
->setSettings([
'datetime_type' => 'date'
])
->setDefaultValueCallback('Drupal\opencase_entities\Entity\OCActivity::currentDateTime')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'datetime_default',
'settings' => [
'format_type' => 'medium',
],
'weight' => -3,
])
->setDisplayOptions('form', [
'type' => 'datetime_default',
'weight' => -3,
]);
setSettings(['datetime_type' => 'date'])
this seems to be to blame. See the switch in the source here - if type is 'date' (implemented as a const) then only show date form element, otherwise show date+ time elements.