diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php index 2c00e62..4fe3813 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -108,11 +108,11 @@ public function getAccount() { */ public function impersonateAccount(AccountInterface $account) { // Prevent session information from being saved and push the previous account. - $this->accountStack[] = $this->account; + array_push($this->accountStack, $this->account); $this->originalSessionSaving = $this->sessionManager->isEnabled(); $this->sessionManager->disable(); $this->setAccount($account); - return $this->account; + return $this; } /** @@ -123,30 +123,32 @@ public function revertAccount() { if (!empty($this->accountStack)) { $this->account = array_pop($this->accountStack); } + else { + throw new \RuntimeException(t('No more account impersonations to revert.')); + } // Restore original session saving status if all impersonations are reverted. if (empty($this->accountStack)) { if ($this->originalSessionSaving) { $this->sessionManager->enable(); } } - return $this->account; + return $this; } /** - /** * {@inheritdoc} */ public function revertAll() { // Restore the original account from the stack. if (!empty($this->accountStack)) { - $this->account = $this->accountStack[0]; + $this->account = array_shift($this->accountStack); $this->accountStack = array(); } // Restore original session saving status if all impersonations are reverted. if ($this->originalSessionSaving) { $this->sessionManager->enable(); } - return $this->account; + return $this; } /** diff --git a/core/lib/Drupal/Core/Session/AccountProxyInterface.php b/core/lib/Drupal/Core/Session/AccountProxyInterface.php index b90ee99..b507150 100644 --- a/core/lib/Drupal/Core/Session/AccountProxyInterface.php +++ b/core/lib/Drupal/Core/Session/AccountProxyInterface.php @@ -41,7 +41,7 @@ public function getAccount(); * call! * * @param \Drupal\Core\Session\AccountInterface - * The account to be impersonated. + * $this. */ public function impersonateAccount(AccountInterface $account); @@ -49,7 +49,7 @@ public function impersonateAccount(AccountInterface $account); * Revert from impersonating another account. * * @return \Drupal\Core\Session\AccountInterface - * The last account that was impersonated. + * $this. */ public function revertAccount(); @@ -60,7 +60,7 @@ public function revertAccount(); * been possibility of multiple impersonations. * * @return \Drupal\Core\Session\AccountInterface - * The original account that was impersonated. + * $this. */ public function revertAll(); }