I am creating a new content type and one of the fields I d like to add owner.
I ve chosen reference - user as the field type Type of item to reference = user
How do I make the default value the name of the current user?
Many Thanks
I am creating a new content type and one of the fields I d like to add owner.
I ve chosen reference - user as the field type Type of item to reference = user
How do I make the default value the name of the current user?
Many Thanks
You can set default values in a hook_ENTITY_TYPE_create:
/**
* Implements hook_ENTITY_TYPE_create() for 'node'.
*/
function mymodule_node_create(\Drupal\node\NodeInterface $node) {
if ($node->getType() == 'my_content_type') {
$node->field_user->target_id = \Drupal::currentUser()->id();
}
}