UserSession
class UserSession implements AccountInterface (View source)
An implementation of the user account interface for the global user.
Properties
| protected int | $uid | User ID. |
|
| protected array | $roles | List of the roles this user has. |
|
| protected string | $access | The Unix timestamp when the user last accessed the site. |
|
| string | $name | The name of this account. |
|
| protected string | $preferred_langcode | The preferred language code of the account. |
|
| protected string | $preferred_admin_langcode | The preferred administrative language code of the account. |
|
| protected string | The email address of this account. |
||
| protected string | $timezone | The timezone of this account. |
Methods
Constructs a new user session.
Returns the user ID or 0 for anonymous.
Returns a list of roles.
Checks whether a user has a certain permission.
Returns TRUE if the account is authenticated.
Returns TRUE if the account is anonymous.
Returns the preferred language code of the account.
Returns the preferred administrative language code of the account.
Returns the unaltered login name of this account.
Returns the unaltered login name of this account.
Returns the display name of this account.
Returns the email address of this account.
Returns the timezone of this account.
The timestamp when the account last accessed the site.
Returns the role storage object.
Details
__construct(array $values = [])
Constructs a new user session.
int
id()
Returns the user ID or 0 for anonymous.
array
getRoles(bool $exclude_locked_roles = FALSE)
Returns a list of roles.
bool
hasPermission(string $permission)
Checks whether a user has a certain permission.
bool
isAuthenticated()
Returns TRUE if the account is authenticated.
bool
isAnonymous()
Returns TRUE if the account is anonymous.
string
getPreferredLangcode(bool $fallback_to_default = TRUE)
Returns the preferred language code of the account.
string
getPreferredAdminLangcode(bool $fallback_to_default = TRUE)
Returns the preferred administrative language code of the account.
Defines which language is used on administrative pages.
string
getUsername()
Returns the unaltered login name of this account.
string
getAccountName()
Returns the unaltered login name of this account.
string|MarkupInterface
getDisplayName()
Returns the display name of this account.
By default, the passed-in object's 'name' property is used if it exists, or else, the site-defined value for the 'anonymous' variable. However, a module may override this by implementing hook_user_format_name_alter(&$name, $account).
string|null
getEmail()
Returns the email address of this account.
string
getTimeZone()
Returns the timezone of this account.
int
getLastAccessedTime()
The timestamp when the account last accessed the site.
A value of 0 means the user has never accessed the site.
protected RoleStorageInterface
getRoleStorage()
Returns the role storage object.