You are here

public function AccountProxy::setAccount in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Session/AccountProxy.php \Drupal\Core\Session\AccountProxy::setAccount()

Sets the currently wrapped account.

Setting the current account is highly discouraged! Instead, make sure to inject the desired user object into the dependent code directly.

A preferable method of account impersonation is to use \Drupal\Core\Session\AccountSwitcherInterface::switchTo() and \Drupal\Core\Session\AccountSwitcherInterface::switchBack().

Parameters

\Drupal\Core\Session\AccountInterface $account: The current account.

Overrides AccountProxyInterface::setAccount

File

core/lib/Drupal/Core/Session/AccountProxy.php, line 40
Contains \Drupal\Core\Session\AccountProxy.

Class

AccountProxy
A proxied implementation of AccountInterface.

Namespace

Drupal\Core\Session

Code

public function setAccount(AccountInterface $account) {

  // If the passed account is already proxied, use the actual account instead
  // to prevent loops.
  if ($account instanceof static) {
    $account = $account
      ->getAccount();
  }
  $this->account = $account;
  date_default_timezone_set(drupal_get_user_timezone());
}