示例#1
0
 /**
  * Masquerades the current user as a given user.
  *
  * Access to masquerade as the target user account has to checked by all callers
  * via masquerade_target_user_access() already.
  *
  * @param \Drupal\user\UserInterface $user
  *   The user account object to masquerade as.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   Redirect to previous page.
  *
  * @see this::getRedirectResponse()
  */
 public function switchTo(UserInterface $user)
 {
     // Store current user for messages.
     $account = $this->currentUser;
     $error = masquerade_switch_user_validate($user);
     if (empty($error)) {
         if ($this->masquerade->switchTo($user)) {
             drupal_set_message($this->t('You are now masquerading as @user.', array('@user' => $account->getDisplayName())));
         }
     } else {
         drupal_set_message($error, 'error');
     }
     return $this->getRedirectResponse();
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->masquerade->switchTo($form_state->getValue('masquerade_target_account'));
 }