protected function getUser($name) {
    $user_storage = $this->entityTypeManager->getStorage('user');
    $users = $user_storage->loadByProperties(['name' => $name]);;
    if (empty($users)) {
      // Creating user without any email/password.
      $user = $user_storage->create([
        'name' => $name,
        'status' => 1,
      ]);
      $user->enforceIsNew();
      $user->save();
      $this->storeCreatedContentUuids([$user->uuid() => 'user']);
      return $user->id();
    }
    $user = reset($users);
    return $user->id();
  }
protected function getUser($name) {
    $user_storage = $this->entityTypeManager->getStorage('user');
    $users = $user_storage->loadByProperties(['name' => $name]);;
    if (empty($users)) {
      // Creating user without any email/password.
      $user = $user_storage->create([
        'name' => $name,
        'status' => 1,
      ]);
      $user->enforceIsNew();
      $user->save();
      $this->storeCreatedContentUuids([$user->uuid() => 'user']);
      return $user->id();
    }
    $user = reset($users);
    return $user->id();
  }
protected function getUser ( $ name ) { $ user_storage = $ this -> entityTypeManager -> getStorage ( 'user' ) ; $ users = $ user_storage -> loadByProperties ( [ 'name' => $ name ] ) ; ; if ( empty ( $ users ) ) { // Creating user without any email/password. $ user = $ user_storage -> create ( [ 'name' => $ name , 'status' => 1 , ] ) ; $ user -> enforceIsNew ( ) ; $ user -> save ( ) ; $ this -> storeCreatedContentUuids ( [ $ user -> uuid ( ) => 'user' ] ) ; return $ user -> id ( ) ; } $ user = reset ( $ users ) ; return $ user -> id ( ) ; }
Looks up a user by name, if it is missing the user is created.

@param string $name
Username.

@return int
User ID.
Looks up a user by name if it is missing the user is created .