function UserStorage::doSaveFieldItems

Overrides SqlContentEntityStorage::doSaveFieldItems

File

core/modules/user/src/UserStorage.php, line 20

Class

UserStorage
Controller class for users.

Namespace

Drupal\user

Code

protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []) {
  // The anonymous user account is saved with the fixed user ID of 0.
  // Therefore we need to check for NULL explicitly.
  if ($entity->id() === NULL) {
    $entity->uid->value = $this->database
      ->nextId($this->database
      ->query('SELECT MAX(uid) FROM {' . $this->getBaseTable() . '}')
      ->fetchField());
    $entity->enforceIsNew();
  }
  return parent::doSaveFieldItems($entity, $names);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.