You are here

protected function UserStorage::doSaveFieldItems in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/UserStorage.php \Drupal\user\UserStorage::doSaveFieldItems()

Writes entity field values to the storage.

This method is responsible for allocating entity and revision identifiers and updating the entity object with their values.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity object.

string[] $names: (optional) The name of the fields to be written to the storage. If an empty value is passed all field values are saved.

Overrides SqlContentEntityStorage::doSaveFieldItems

File

core/modules/user/src/UserStorage.php, line 75
Contains \Drupal\user\UserStorage.

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 {users}')
      ->fetchField());
    $entity
      ->enforceIsNew();
  }
  return parent::doSaveFieldItems($entity, $names);
}