You are here

class ContentHubUserSession in Acquia Content Hub 8

Same name and namespace in other branches
  1. 8.2 src/Session/ContentHubUserSession.php \Drupal\acquia_contenthub\Session\ContentHubUserSession

An account implementation representing a Content Hub user.

Hierarchy

Expanded class hierarchy of ContentHubUserSession

8 files declare their use of ContentHubUserSession
ContentEntityCdfNormalizer.php in src/Normalizer/ContentEntityCdfNormalizer.php
ContentEntityNormalizerTest.php in tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
ContentEntityViewModesExtractor.php in src/Normalizer/ContentEntityViewModesExtractor.php
ContentHubInternalRequest.php in src/ContentHubInternalRequest.php
ContentHubUserSessionTest.php in tests/src/Unit/Session/ContentHubUserSessionTest.php

... See full list

File

src/Session/ContentHubUserSession.php, line 11

Namespace

Drupal\acquia_contenthub\Session
View source
class ContentHubUserSession extends UserSession {

  /**
   * Role used to render Content Hub content.
   *
   * @var string
   */
  protected $renderRole;

  /**
   * Constructs a new Content Hub user session.
   *
   * @param string $render_role
   *   Role id.
   */
  public function __construct($render_role) {
    $this->renderRole = $render_role;
    parent::__construct([
      'roles' => $this
        ->getContentHubRenderUserRoles($render_role),
    ]);
  }

  /**
   * Obtains the user roles based on the module settings.
   *
   * @param string $render_role
   *   Role to view content.
   *
   * @return array
   *   Array of roles.
   */
  private function getContentHubRenderUserRoles($render_role) {
    switch ($render_role) {
      case AccountInterface::ANONYMOUS_ROLE:
      case AccountInterface::AUTHENTICATED_ROLE:
        $roles = [
          $render_role,
        ];
        break;
      default:
        $roles = [
          AccountInterface::AUTHENTICATED_ROLE,
          $render_role,
        ];
        break;
    }
    return $roles;
  }

  /**
   * {@inheritdoc}
   */
  public function isAuthenticated() {
    return $this->renderRole !== AccountInterface::ANONYMOUS_ROLE;
  }

  /**
   * {@inheritdoc}
   */
  public function isAnonymous() {
    return $this->renderRole === AccountInterface::ANONYMOUS_ROLE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AccountInterface::ANONYMOUS_ROLE constant Role ID for anonymous users.
AccountInterface::AUTHENTICATED_ROLE constant Role ID for authenticated users.
ContentHubUserSession::$renderRole protected property Role used to render Content Hub content.
ContentHubUserSession::getContentHubRenderUserRoles private function Obtains the user roles based on the module settings.
ContentHubUserSession::isAnonymous public function Returns TRUE if the account is anonymous. Overrides UserSession::isAnonymous
ContentHubUserSession::isAuthenticated public function Returns TRUE if the account is authenticated. Overrides UserSession::isAuthenticated
ContentHubUserSession::__construct public function Constructs a new Content Hub user session. Overrides UserSession::__construct
UserSession::$access protected property The Unix timestamp when the user last accessed the site.
UserSession::$mail protected property The email address of this account.
UserSession::$name public property The name of this account.
UserSession::$preferred_admin_langcode protected property The preferred administrative language code of the account.
UserSession::$preferred_langcode protected property The preferred language code of the account.
UserSession::$roles protected property List of the roles this user has.
UserSession::$timezone protected property The timezone of this account.
UserSession::$uid protected property User ID.
UserSession::getAccountName public function Returns the unaltered login name of this account. Overrides AccountInterface::getAccountName
UserSession::getDisplayName public function Returns the display name of this account. Overrides AccountInterface::getDisplayName
UserSession::getEmail public function Returns the email address of this account. Overrides AccountInterface::getEmail
UserSession::getLastAccessedTime public function The timestamp when the account last accessed the site. Overrides AccountInterface::getLastAccessedTime
UserSession::getPreferredAdminLangcode public function Returns the preferred administrative language code of the account. Overrides AccountInterface::getPreferredAdminLangcode
UserSession::getPreferredLangcode public function Returns the preferred language code of the account. Overrides AccountInterface::getPreferredLangcode
UserSession::getRoles public function Returns a list of roles. Overrides AccountInterface::getRoles
UserSession::getRoleStorage protected function Returns the role storage object.
UserSession::getTimeZone public function Returns the timezone of this account. Overrides AccountInterface::getTimeZone
UserSession::getUsername public function Returns the unaltered login name of this account. Overrides AccountInterface::getUsername
UserSession::hasPermission public function Checks whether a user has a certain permission. Overrides AccountInterface::hasPermission
UserSession::id public function Returns the user ID or 0 for anonymous. Overrides AccountInterface::id