User8.php

  1. 8.0.x lib/Drush/User/User8.php
  2. 7.x lib/Drush/User/User8.php
  3. master lib/Drush/User/User8.php

Namespace

Drush\User

Classes

Namesort descending Description
User8

File

lib/Drush/User/User8.php
View source
  1. <?php
  2. namespace Drush\User;
  3. use Drupal\user\Entity\User;
  4. class User8 extends UserVersion {
  5. /**
  6. * {inheritdoc}
  7. */
  8. public function create($properties) {
  9. $account = entity_create('user', $properties);
  10. $account->save();
  11. return new UserSingle8($account);
  12. }
  13. /**
  14. * Attempt to load a user account.
  15. *
  16. * @param int $uid
  17. * @return \Drupal\user\Entity\User;
  18. */
  19. public function load_by_uid($uid) {
  20. return User::load($uid);
  21. }
  22. /**
  23. * {inheritdoc}
  24. */
  25. public function getCurrentUserAsAccount() {
  26. return \Drupal::currentUser()->getAccount();
  27. }
  28. /**
  29. * Set the current user in Drupal.
  30. *
  31. * @param \Drupal\Core\Session\AccountInterface $account
  32. */
  33. public function setCurrentUser($account) {
  34. // Some parts of Drupal still rely on a global user object.
  35. // @todo remove once https://www.drupal.org/node/2163205 is in.
  36. global $user;
  37. $user = $account;
  38. \Drupal::currentUser()->setAccount($account);
  39. }
  40. }