3 namespace Drupal\Core\Session;
6 * Defines an account interface which represents the current user.
8 * Defines an object that has a user id, roles and can have session data. The
9 * interface is implemented both by the global session and the user entity.
13 interface AccountInterface {
16 * Role ID for anonymous users.
18 const ANONYMOUS_ROLE = 'anonymous';
21 * Role ID for authenticated users.
23 const AUTHENTICATED_ROLE = 'authenticated';
26 * Returns the user ID or 0 for anonymous.
34 * Returns a list of roles.
36 * @param bool $exclude_locked_roles
37 * (optional) If TRUE, locked roles (anonymous/authenticated) are not returned.
42 public function getRoles($exclude_locked_roles = FALSE);
45 * Checks whether a user has a certain permission.
47 * @param string $permission
48 * The permission string to check.
51 * TRUE if the user has the permission, FALSE otherwise.
53 public function hasPermission($permission);
56 * Returns TRUE if the account is authenticated.
59 * TRUE if the account is authenticated.
61 public function isAuthenticated();
64 * Returns TRUE if the account is anonymous.
67 * TRUE if the account is anonymous.
69 public function isAnonymous();
72 * Returns the preferred language code of the account.
74 * @param bool $fallback_to_default
75 * (optional) Whether the return value will fall back to the site default
76 * language if the user has no language preference.
79 * The language code that is preferred by the account. If the preferred
80 * language is not set or is a language not configured anymore on the site,
81 * the site default is returned or an empty string is returned (if
82 * $fallback_to_default is FALSE).
84 public function getPreferredLangcode($fallback_to_default = TRUE);
87 * Returns the preferred administrative language code of the account.
89 * Defines which language is used on administrative pages.
91 * @param bool $fallback_to_default
92 * (optional) Whether the return value will fall back to the site default
93 * language if the user has no administration language preference.
96 * The language code that is preferred by the account for administration
97 * pages. If the preferred language is not set or is a language not
98 * configured anymore on the site, the site default is returned or an empty
99 * string is returned (if $fallback_to_default is FALSE).
101 public function getPreferredAdminLangcode($fallback_to_default = TRUE);
104 * Returns the unaltered login name of this account.
107 * An unsanitized plain-text string with the name of this account that is
108 * used to log in. Only display this name to admins and to the user who owns
109 * this account, and only in the context of the name used to log in. For
110 * any other display purposes, use
111 * \Drupal\Core\Session\AccountInterface::getDisplayName() instead.
113 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
114 * Use \Drupal\Core\Session\AccountInterface::getAccountName() or
115 * \Drupal\user\UserInterface::getDisplayName() instead.
117 public function getUsername();
120 * Returns the unaltered login name of this account.
123 * An unsanitized plain-text string with the name of this account that is
124 * used to log in. Only display this name to admins and to the user who owns
125 * this account, and only in the context of the name used to login. For
126 * any other display purposes, use
127 * \Drupal\Core\Session\AccountInterface::getDisplayName() instead.
129 public function getAccountName();
132 * Returns the display name of this account.
134 * By default, the passed-in object's 'name' property is used if it exists, or
135 * else, the site-defined value for the 'anonymous' variable. However, a
136 * module may override this by implementing
137 * hook_user_format_name_alter(&$name, $account).
139 * @see hook_user_format_name_alter()
141 * @return string|\Drupal\Component\Render\MarkupInterface
142 * Either a string that will be auto-escaped on output or a
143 * MarkupInterface object that is already HTML escaped. Either is safe
144 * to be printed within HTML fragments.
146 public function getDisplayName();
149 * Returns the email address of this account.
154 public function getEmail();
157 * Returns the timezone of this account.
160 * Name of the timezone.
162 public function getTimeZone();
165 * The timestamp when the account last accessed the site.
167 * A value of 0 means the user has never accessed the site.
170 * Timestamp of the last access.
172 public function getLastAccessedTime();