SHARE
TWEET

Untitled

a guest Sep 20th, 2016 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. # Create user
  3. $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
  4. $user = \Drupal\user\Entity\User::create();
  5.  
  6. $user->setUsername('username');
  7. $user->setEmail('email@test.com');
  8. $password = hash('sha512',uniqid(rand(), true));
  9. $user->setPassword($password);
  10. $user->addRole('role_machine_name');
  11. $user->enforceIsNew();
  12. $user->activate();
  13. $result = $user->save();
  14.  
  15. # Edit user
  16. $user_load = user_load_by_name($old_email);
  17. $user = \Drupal\user\Entity\User::load($user_load->id());
  18. $user->setUsername($new_email);
  19. $user->setEmail($new_email);
  20. $user->save();
  21.  
  22. # Delete user
  23. $user_load = user_load_by_name($email);
  24. $user = \Drupal\user\Entity\User::load($user_load->id());
  25. $user->delete();
  26. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top