Drupal 8  8.0.2
AccountInterface Interface Reference
Inheritance diagram for AccountInterface:

Public Member Functions

 id ()
 
 getRoles ($exclude_locked_roles=FALSE)
 
 hasPermission ($permission)
 
 isAuthenticated ()
 
 isAnonymous ()
 
 getPreferredLangcode ($fallback_to_default=TRUE)
 
 getPreferredAdminLangcode ($fallback_to_default=TRUE)
 
 getUsername ()
 
 getAccountName ()
 
 getDisplayName ()
 
 getEmail ()
 
 getTimeZone ()
 
 getLastAccessedTime ()
 

Data Fields

const ANONYMOUS_ROLE = 'anonymous'
 
const AUTHENTICATED_ROLE = 'authenticated'
 

Detailed Description

Defines an account interface which represents the current user.

Defines an object that has a user id, roles and can have session data. The interface is implemented both by the global session and the user entity.

Member Function Documentation

getAccountName ( )

Returns the unaltered login name of this account.

Returns
string An unsanitized plain-text string with the name of this account that is used to log in. Only display this name to admins and to the user who owns this account, and only in the context of the name used to login. For any other display purposes, use ::getDisplayName() instead.

Implemented in User, UserSession, and AccountProxy.

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).

See Also
hook_user_format_name_alter()
Returns
string| Either a string that will be auto-escaped on output or a MarkupInterface object that is already HTML escaped. Either is safe to be printed within HTML fragments.

Implemented in User, UserSession, and AccountProxy.

Referenced by ContactController\contactPersonalPage().

Here is the caller graph for this function:

getEmail ( )

Returns the email address of this account.

Returns
string The email address.

Implemented in User, UserSession, and AccountProxy.

Referenced by ContactController\contactPersonalPage().

Here is the caller graph for this function:

getLastAccessedTime ( )

The timestamp when the account last accessed the site.

A value of 0 means the user has never accessed the site.

Returns
int Timestamp of the last access.

Implemented in User, UserSession, and AccountProxy.

getPreferredAdminLangcode (   $fallback_to_default = TRUE)

Returns the preferred administrative language code of the account.

Defines which language is used on administrative pages.

Parameters
bool$fallback_to_default(optional) Whether the return value will fall back to the site default language if the user has no administration language preference.
Returns
string The language code that is preferred by the account for administration pages. If the preferred language is not set or is a language not configured anymore on the site, the site default is returned or an empty string is returned (if $fallback_to_default is FALSE).

Implemented in User, UserSession, and AccountProxy.

getPreferredLangcode (   $fallback_to_default = TRUE)

Returns the preferred language code of the account.

Parameters
bool$fallback_to_default(optional) Whether the return value will fall back to the site default language if the user has no language preference.
Returns
string The language code that is preferred by the account. If the preferred language is not set or is a language not configured anymore on the site, the site default is returned or an empty string is returned (if $fallback_to_default is FALSE).

Implemented in User, UserSession, and AccountProxy.

getRoles (   $exclude_locked_roles = FALSE)

Returns a list of roles.

Parameters
bool$exclude_locked_roles(optional) If TRUE, locked roles (anonymous/authenticated) are not returned.
Returns
array List of role IDs.

Implemented in User, UserSession, and AccountProxy.

Referenced by RoleAccessCheck\access(), Role\access(), and PermissionsHashGenerator\generate().

Here is the caller graph for this function:

getTimeZone ( )

Returns the timezone of this account.

Returns
string Name of the timezone.

Implemented in User, UserSession, and AccountProxy.

getUsername ( )

Returns the unaltered login name of this account.

Returns
string An unsanitized plain-text string with the name of this account that is used to log in. Only display this name to admins and to the user who owns this account, and only in the context of the name used to login. For any other display purposes, use ::getDisplayName() instead.
Deprecated:
in Drupal 8.0.0, will be removed before Drupal 9.0.0. Use ::getAccountName() or ::getDisplayName() instead.

Implemented in User, UserSession, and AccountProxy.

Referenced by ContentTranslationWorkflowsTest\doTestWorkflows(), and TrackerUserTab\getTitle().

Here is the caller graph for this function:

hasPermission (   $permission)

Checks whether a user has a certain permission.

Parameters
string$permissionThe permission string to check.
Returns
bool TRUE if the user has the permission, FALSE otherwise.

Implemented in User, UserSession, and AccountProxy.

Referenced by ContentTranslationOverviewAccess\access(), ContentTranslationManageAccessCheck\access(), Permission\access(), BookManager\addFormElements(), AccessResult\allowedIfHasPermission(), AccessResult\allowedIfHasPermissions(), ContactFormAccessControlHandler\checkAccess(), UserAccessControlHandler\checkFieldAccess(), and MaintenanceMode\exempt().

Here is the caller graph for this function:

isAnonymous ( )

Returns TRUE if the account is anonymous.

Returns
bool TRUE if the account is anonymous.

Implemented in User, UserSession, and AccountProxy.

Referenced by RegisterAccessCheck\access(), UserLoginBlock\blockAccess(), and UserAccessControlHandler\checkFieldAccess().

Here is the caller graph for this function:

isAuthenticated ( )

Returns TRUE if the account is authenticated.

Returns
bool TRUE if the account is authenticated.

Implemented in User, UserSession, and AccountProxy.

Referenced by ViewOwnTrackerAccessCheck\access(), LoginStatusCheck\access(), and CSRFAccessCheck\access().

Here is the caller graph for this function:

Field Documentation

const ANONYMOUS_ROLE = 'anonymous'

Role ID for anonymous users.

Referenced by UserSession\getRoles(), ResourceTest\setUp(), and FieldEntityLinkTest\setUpFixtures().

const AUTHENTICATED_ROLE = 'authenticated'

Role ID for authenticated users.

Referenced by UserSession\getRoles(), and Cookie\getUserFromSession().


The documentation for this interface was generated from the following file: