function AccountSwitcher::switchBack

Same name in other branches
  1. 9 core/lib/Drupal/Core/Session/AccountSwitcher.php \Drupal\Core\Session\AccountSwitcher::switchBack()
  2. 8.9.x core/lib/Drupal/Core/Session/AccountSwitcher.php \Drupal\Core\Session\AccountSwitcher::switchBack()
  3. 10 core/lib/Drupal/Core/Session/AccountSwitcher.php \Drupal\Core\Session\AccountSwitcher::switchBack()

Overrides AccountSwitcherInterface::switchBack

File

core/lib/Drupal/Core/Session/AccountSwitcher.php, line 73

Class

AccountSwitcher
An implementation of AccountSwitcherInterface.

Namespace

Drupal\Core\Session

Code

public function switchBack() {
    // Restore the previous account from the stack.
    if (!empty($this->accountStack)) {
        $this->currentUser
            ->setAccount(array_pop($this->accountStack));
    }
    else {
        throw new \RuntimeException('No more accounts to revert to.');
    }
    // Restore original session saving status if all account switches are
    // reverted.
    if (empty($this->accountStack)) {
        if ($this->originalSessionSaving) {
            $this->writeSafeHandler
                ->setSessionWritable(TRUE);
        }
    }
    return $this;
}

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