Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     $this->data['name'] = $this->currentUser->getDisplayName();
     $this->data['authenticated'] = $this->currentUser->isAuthenticated();
     $this->data['roles'] = [];
     $storage = $this->entityManager->getStorage('user_role');
     foreach ($this->currentUser->getRoles() as $role) {
         $entity = $storage->load($role);
         $this->data['roles'][] = $entity->label();
     }
     foreach ($this->providerCollector->getSortedProviders() as $provider_id => $provider) {
         if ($provider->applies($request)) {
             $this->data['provider'] = $provider_id;
         }
     }
     $this->data['anonymous'] = $this->configFactory->get('user.settings')->get('anonymous');
 }
Esempio n. 2
0
 /**
  * Display a given user's identity.
  *
  * @param \Drupal\Core\Session\AccountInterface|NULL $user
  *   The user to retrieve data on behalf of.
  *
  * @return array
  *   Render array with all the results.
  */
 public function display(AccountInterface $user = NULL)
 {
     // Build the output (as a render array).
     $output = ['#cache' => ['max-age' => 0]];
     if ($user) {
         $output['name'] = ['#markup' => $this->t('Name: %name', ['%name' => $user->getDisplayName()])];
         $output['mail'] = ['#markup' => $this->t('Mail: %mail', ['%mail' => $user->getEmail()])];
     }
     return $output;
 }