function AccountProxyInterface::setAccount

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Session/AccountProxyInterface.php \Drupal\Core\Session\AccountProxyInterface::setAccount()
  2. 10 core/lib/Drupal/Core/Session/AccountProxyInterface.php \Drupal\Core\Session\AccountProxyInterface::setAccount()
  3. 11.x core/lib/Drupal/Core/Session/AccountProxyInterface.php \Drupal\Core\Session\AccountProxyInterface::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.

1 method overrides AccountProxyInterface::setAccount()
AccountProxy::setAccount in core/lib/Drupal/Core/Session/AccountProxy.php
Sets the currently wrapped account.

File

core/lib/Drupal/Core/Session/AccountProxyInterface.php, line 30

Class

AccountProxyInterface
Defines an interface for a service which has the current account stored.

Namespace

Drupal\Core\Session

Code

public function setAccount(AccountInterface $account);

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.