class ContentHubUserSession in Acquia Content Hub 8
Same name and namespace in other branches
- 8.2 src/Session/ContentHubUserSession.php \Drupal\acquia_contenthub\Session\ContentHubUserSession
An account implementation representing a Content Hub user.
Hierarchy
- class \Drupal\Core\Session\UserSession implements AccountInterface
- class \Drupal\acquia_contenthub\Session\ContentHubUserSession
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
File
- src/
Session/ ContentHubUserSession.php, line 11
Namespace
Drupal\acquia_contenthub\SessionView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccountInterface:: |
constant | Role ID for anonymous users. | ||
AccountInterface:: |
constant | Role ID for authenticated users. | ||
ContentHubUserSession:: |
protected | property | Role used to render Content Hub content. | |
ContentHubUserSession:: |
private | function | Obtains the user roles based on the module settings. | |
ContentHubUserSession:: |
public | function |
Returns TRUE if the account is anonymous. Overrides UserSession:: |
|
ContentHubUserSession:: |
public | function |
Returns TRUE if the account is authenticated. Overrides UserSession:: |
|
ContentHubUserSession:: |
public | function |
Constructs a new Content Hub user session. Overrides UserSession:: |
|
UserSession:: |
protected | property | The Unix timestamp when the user last accessed the site. | |
UserSession:: |
protected | property | The email address of this account. | |
UserSession:: |
public | property | The name of this account. | |
UserSession:: |
protected | property | The preferred administrative language code of the account. | |
UserSession:: |
protected | property | The preferred language code of the account. | |
UserSession:: |
protected | property | List of the roles this user has. | |
UserSession:: |
protected | property | The timezone of this account. | |
UserSession:: |
protected | property | User ID. | |
UserSession:: |
public | function |
Returns the unaltered login name of this account. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
Returns the display name of this account. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
Returns the email address of this account. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
The timestamp when the account last accessed the site. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
Returns the preferred administrative language code of the account. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
Returns the preferred language code of the account. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
Returns a list of roles. Overrides AccountInterface:: |
|
UserSession:: |
protected | function | Returns the role storage object. | |
UserSession:: |
public | function |
Returns the timezone of this account. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
Returns the unaltered login name of this account. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
Checks whether a user has a certain permission. Overrides AccountInterface:: |
|
UserSession:: |
public | function |
Returns the user ID or 0 for anonymous. Overrides AccountInterface:: |