public AccountProxy::setAccount(AccountInterface $account)
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 35
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());
}
 
          
Please login to continue.