drupal create user

Solutions on MaxInterview for drupal create user by the best coders in the world

showing results for - "drupal create user"
Aarón
31 Sep 2016
1
2$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
3$user = \Drupal\user\Entity\User::create();
4
5//Mandatory settings
6$user->setPassword('test');
7$user->enforceIsNew();
8$user->setEmail('test@test.com');
9$user->setUsername('test'); //This username must be unique and accept only a-Z,0-9, - _ @ .
10
11//Optional settings
12$user->set("init", 'email');
13$user->set("langcode", $language);
14$user->set("preferred_langcode", $language);
15$user->set("preferred_admin_langcode", $language);
16//$user->set("setting_name", 'setting_value');
17$user->activate();
18
19//Save user
20$user->save();