You are here

public function UserSessionState::switchUser in RESTful 7.2

Make the passed in user to be the account for the Drupal thread.

Parameters

object $account: The account to switch to.

Overrides UserSessionStateInterface::switchUser

File

src/Authentication/UserSessionState.php, line 50
Contains \Drupal\restful\Authentication\UserSessionState.

Class

UserSessionState
Class UserSessionState.

Namespace

Drupal\restful\Authentication

Code

public function switchUser($account) {
  global $user;
  if (!static::isSwitched() && !$this->originalUser && !$this->needsSaving) {

    // This is the first time a user switched, and there isn't an original
    // user session.
    $this->needsSaving = drupal_save_session();
    $this->originalUser = $user;

    // Don't allow a session to be saved. Provider that require a session to
    // be saved, like the cookie provider, need to explicitly set
    // drupal_save_session(TRUE).
    // @see LoginCookie__1_0::loginUser().
    drupal_save_session(FALSE);
  }

  // Set the global user.
  $user = $account;
}