drupal 8 create user programmatically code example
Example 1: drupal 8 get user
$current_user = \Drupal::currentUser();
$user = \Drupal\user\Entity\User::load($current_user->id());
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
Example 2: drupal create user
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$user = \Drupal\user\Entity\User::create();
$user->setPassword('test');
$user->enforceIsNew();
$user->setEmail('[email protected]');
$user->setUsername('test');
$user->set("init", 'email');
$user->set("langcode", $language);
$user->set("preferred_langcode", $language);
$user->set("preferred_admin_langcode", $language);
$user->activate();
$user->save();