You are here

class UserDataCollector in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/DataCollector/UserDataCollector.php \Drupal\webprofiler\DataCollector\UserDataCollector
  2. 8.2 webprofiler/src/DataCollector/UserDataCollector.php \Drupal\webprofiler\DataCollector\UserDataCollector
  3. 4.x webprofiler/src/DataCollector/UserDataCollector.php \Drupal\webprofiler\DataCollector\UserDataCollector

Class UserDataCollector

Hierarchy

Expanded class hierarchy of UserDataCollector

1 string reference to 'UserDataCollector'
webprofiler.services.yml in webprofiler/webprofiler.services.yml
webprofiler/webprofiler.services.yml
1 service uses UserDataCollector
webprofiler.user in webprofiler/webprofiler.services.yml
Drupal\webprofiler\DataCollector\UserDataCollector

File

webprofiler/src/DataCollector/UserDataCollector.php, line 18

Namespace

Drupal\webprofiler\DataCollector
View source
class UserDataCollector extends DataCollector implements DrupalDataCollectorInterface {
  use StringTranslationTrait, DrupalDataCollectorTrait;

  /**
   * @var \Drupal\Core\Session\AccountInterface
   */
  private $currentUser;

  /**
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  private $entityManager;

  /**
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  private $configFactory;

  /**
   * @var \Drupal\Core\Authentication\AuthenticationCollectorInterface
   */
  private $providerCollector;

  /**
   * @param \Drupal\Core\Session\AccountInterface $currentUser
   * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   * @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $providerCollector
   */
  public function __construct(AccountInterface $currentUser, EntityManagerInterface $entityManager, ConfigFactoryInterface $configFactory, AuthenticationCollectorInterface $providerCollector) {
    $this->currentUser = $currentUser;
    $this->entityManager = $entityManager;
    $this->configFactory = $configFactory;
    $this->providerCollector = $providerCollector;
  }

  /**
   * {@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');
  }

  /**
   * @return \Drupal\Core\Session\AccountInterface
   */
  public function getUserName() {
    return $this->data['name'];
  }

  /**
   * @return bool
   */
  public function getAuthenticated() {
    return $this->data['authenticated'];
  }

  /**
   * @return array
   */
  public function getRoles() {
    return $this->data['roles'];
  }

  /**
   * @return string
   */
  public function getProvider() {
    return $this->data['provider'];
  }

  /**
   * @return string
   */
  public function getAnonymous() {
    return $this->data['anonymous'];
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'user';
  }

  /**
   * {@inheritdoc}
   */
  public function getTitle() {
    return $this
      ->t('User');
  }

  /**
   * {@inheritdoc}
   */
  public function getPanelSummary() {
    return $this
      ->getUserName();
  }

  /**
   * {@inheritdoc}
   */
  public function getIcon() {
    return 'iVBORw0KGgoAAAANSUhEUgAAABgAAAAcCAYAAAB75n/uAAAC70lEQVR42u2V3UtTYRzHu+mFwCwK+gO6CEryPlg7yiYx50vDqUwjFIZDSYUk2ZTmCysHvg9ZVggOQZiRScsR4VwXTjEwdKZWk8o6gd5UOt0mbev7g/PAkLONIOkiBx+25/v89vuc85zn2Q5Fo9F95UDwnwhS5HK5TyqVRv8m1JN6k+AiC+fn54cwbgFNIrTQ/J9IqDcJJDGBHsgDgYBSq9W6ysvLPf39/SSUUU7zsQ1yc3MjmN90OBzfRkZG1umzQqGIxPSTkIBjgdDkaGNjoza2kcFgUCE/QvMsq6io2PV6vQu1tbV8Xl7etkql2qqvr/+MbDE/Pz8s9OP2Cjhwwmw29+4R3Kec1WZnZ4fn5uamc3Jyttra2qbH8ero6JgdHh5+CvFHq9X6JZHgzODgoCVW0NPTY0N+ltU2Nzdv4GqXsYSrPp+vDw80aLFYxru6uhyQ/rDb7a8TCVJDodB1jUazTVlxcXGQ5/mbyE+z2u7u7veY38BVT3Z2djopm5qa6isrK/tQWVn5qb29fSGR4DC4PDAwMEsZHuArjGnyGKutq6v7ajQaF6urq9/MzMz0QuSemJiwQDwGkR0POhhXgILjNTU1TaWlpTxlOp1uyWQyaUjMajMzM8Nut/tJQUHBOpZppbCwkM/KytrBznuL9xDVxBMo8KXHYnu6qKjIivmrbIy67x6Px4Yd58W672ApfzY0NCyNjo7OZmRkiAv8fr+O47iwmABXtoXaG3uykF6vX7bZbF6cgZWqqiqezYkKcNtmjO+CF2AyhufgjsvlMiU7vXEF+4C4ALf9CwdrlVAqlcFkTdRqdQSHLUDgBEeSCrArAsiGwENs0XfJBE6ncxm1D8Aj/B6tigkkJSUlmxSwLYhMDeRsyyUCd+lHrWxtbe2aTCbbZTn1ZD92F0Cr8GBfgnsgDZwDt8EzMBmHMXBLqD0PDMAh9Gql3iRIESQSIAXp4CRIBZeEjIvDFZAm1J4C6UK9ROiZcvCn/+8FvwHtDdJEaRY+oQAAAABJRU5ErkJggg==';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDataCollectorInterface::getData public function 8
DrupalDataCollectorInterface::getDrupalSettings public function 1
DrupalDataCollectorInterface::getLibraries public function Returns the libraries needed in detail panel. 2
DrupalDataCollectorInterface::hasPanel public function Returns true if this datacollector has a detail panel. 2
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UserDataCollector::$configFactory private property
UserDataCollector::$currentUser private property
UserDataCollector::$entityManager private property
UserDataCollector::$providerCollector private property
UserDataCollector::collect public function Collects data for the given Request and Response.
UserDataCollector::getAnonymous public function
UserDataCollector::getAuthenticated public function
UserDataCollector::getIcon public function Returns the collector icon in base64 format. Overrides DrupalDataCollectorInterface::getIcon
UserDataCollector::getName public function Returns the name of the collector. Overrides DrupalDataCollectorInterface::getName
UserDataCollector::getPanelSummary public function Returns the string used in vertical tab summary. Overrides DrupalDataCollectorInterface::getPanelSummary
UserDataCollector::getProvider public function
UserDataCollector::getRoles public function
UserDataCollector::getTitle public function Returns the datacollector title. Overrides DrupalDataCollectorInterface::getTitle
UserDataCollector::getUserName public function
UserDataCollector::__construct public function