How to insert value to user entity custom field while creating new account? I am trying to insert a value into a custom field(field_custom_referral) which is created in the backend.When a user creating a account in our application, this particular custom field should be updated with custom value. Can anyone help me out here.

I tried below code in .module file but not working out:

function module_user_insert(Drupal\Core\Entity\EntityTypeInterface $entity) {
  $entity-&gt;set('field_custom_referral', '3');
  $entity-&gt;save();
}


Any suggestion will be appreciated.
The hook_ENTITY_TYPE_insert in case of entity user expecting Drupal\user\UserInterface instance not Drupal\Core\Entity\EntityTypeInterface

change your hook to:

/**
 * Implements hook_ENTITY_TYPE_insert().
 */
function MYMODULE_user_insert(Drupal\user\UserInterface $user) {
  $user-&gt;set('field_custom_referral', '3');
  $user-&gt;save();
}