You are here

public function FeedsAccountSwitcher::switchTo in Feeds 7.2

Safely switches to another account.

Each invocation of FeedsAccountSwitcherInterface::switchTo() must be matched by a corresponding invocation of FeedsAccountSwitcherInterface::switchBack() in the same function.

Parameters

object $account: The account to switch to.

Return value

FeedsAccountSwitcherInterface $this.

Overrides FeedsAccountSwitcherInterface::switchTo

File

includes/FeedsAccountSwitcher.inc, line 57
Contains FeedsAccountSwitcher class.

Class

FeedsAccountSwitcher
An implementation of FeedsAccountSwitcherInterface.

Code

public function switchTo($account) {

  // Prevent session information from being saved and push previous account.
  if (!isset($this->originalSessionSave)) {

    // Ensure that only the first session saving status is saved.
    $this->originalSessionSave = drupal_save_session();
    drupal_save_session(FALSE);
  }
  array_push($this->accountStack, $this->currentUser);
  $this->currentUser = $account;
  $this
    ->activateCurrentUser();
  return $this;
}