ContentHubUserSession.php in Acquia Content Hub 8.2
File
src/Session/ContentHubUserSession.php
View source
<?php
namespace Drupal\acquia_contenthub\Session;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\UserSession;
class ContentHubUserSession extends UserSession {
protected $renderRole;
public function __construct($render_role) {
$this->renderRole = $render_role;
parent::__construct([
'roles' => $this
->getContentHubRenderUserRoles($render_role),
]);
}
protected 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;
}
public function isAuthenticated() {
return $this->renderRole !== AccountInterface::ANONYMOUS_ROLE;
}
public function isAnonymous() {
return $this->renderRole === AccountInterface::ANONYMOUS_ROLE;
}
}