I have a custom content entity 'service' created with Drupal Console (drupal generate:entity:content).
I added my own fields to the standard ones created by DC. Of which 'seliste_id':
$fields['seliste_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('SEListe'))
->setSetting('target_type', 'person')
->setSetting('handler', 'default');
By default, the code generated by DC handles the owner of any new entity, owner_id being the id of the current user.
By design, seliste_id is the id of the other entity 'person' which is linked 1 <-> 1 to Drupal's 'user'.
So when a new 'service' is created, I'd like to "copy" its owner (i.e. the current user's id) to 'seliste_id'.
I know that I can do that in mymodule_entity_presave().
Is there a way to do that in the definition of 'seliste_id' field?
With ->setDefaultValue()
or ->setDefaultValueCallback()
maybe?
Any idea?