Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function blockAccess(AccountInterface $account)
 {
     if ($this->masquerade->isMasquerading()) {
         return AccessResult::forbidden()->addCacheContexts(['is_masquerading']);
     }
     // Display block for all users that has any of masquerade permissions.
     return AccessResult::allowedIfHasPermissions($account, $this->masquerade->getPermissions(), 'OR');
 }
Exemplo n.º 2
0
 /**
  * Check to see if user has any permissions to masquerade.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   Run access checks for this account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(AccountInterface $account)
 {
     // Uid 1 may masquerade as anyone.
     if ($account->id() == 1) {
         return AccessResult::allowed()->cachePerUser();
     }
     $permissions = $this->masquerade->getPermissions();
     return AccessResult::allowedIfHasPermissions($account, $permissions, 'OR');
 }
Exemplo n.º 3
0
 /**
  * Allows a user who is currently masquerading to become a new user.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   Redirect response to previous page.
  *
  * @see this::getRedirectResponse()
  */
 public function switchBack(Request $request)
 {
     // Store current user name for messages.
     $account_name = $this->currentUser->getDisplayName();
     if ($this->masquerade->switchBack()) {
         drupal_set_message($this->t('You are no longer masquerading as @user.', array('@user' => $account_name)));
     } else {
         drupal_set_message($this->t('Error trying unmasquerading as @user.', array('@user' => $account_name)), 'error');
     }
     return $this->getRedirectResponse($request);
 }
 /**
  * Check to see if user is masquerading.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access()
 {
     return AccessResult::allowedIf($this->masquerade->isMasquerading())->addCacheContexts(['is_masquerading']);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->masquerade->switchTo($form_state->getValue('masquerade_target_account'));
 }