Drupal  8.2.6
API documentation
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes
User Class Reference
Inheritance diagram for User:
ContentEntityBase UserInterface Entity ContentEntityInterface ContentEntityInterface EntityChangedInterface AccountInterface TranslatableInterface RevisionableInterface FieldableEntityInterface TranslatableInterface RevisionableInterface FieldableEntityInterface EntityInterface

Public Member Functions

 isNew ()
 
 preSave (EntityStorageInterface $storage)
 
 postSave (EntityStorageInterface $storage, $update=TRUE)
 
 getRoles ($exclude_locked_roles=FALSE)
 
 hasRole ($rid)
 
 addRole ($rid)
 
 removeRole ($rid)
 
 hasPermission ($permission)
 
 getPassword ()
 
 setPassword ($password)
 
 getEmail ()
 
 setEmail ($mail)
 
 getCreatedTime ()
 
 getLastAccessedTime ()
 
 setLastAccessTime ($timestamp)
 
 getLastLoginTime ()
 
 setLastLoginTime ($timestamp)
 
 isActive ()
 
 isBlocked ()
 
 activate ()
 
 block ()
 
 getTimeZone ()
 
 getPreferredLangcode ($fallback_to_default=TRUE)
 
 getPreferredAdminLangcode ($fallback_to_default=TRUE)
 
 getInitialEmail ()
 
 isAuthenticated ()
 
 isAnonymous ()
 
 getUsername ()
 
 getAccountName ()
 
 getDisplayName ()
 
 setUsername ($username)
 
 setExistingPassword ($password)
 
 checkExistingPassword (UserInterface $account_unchanged)
 
- Public Member Functions inherited from ContentEntityBase
 __construct (array $values, $entity_type, $bundle=FALSE, $translations=array())
 
 postCreate (EntityStorageInterface $storage)
 
 setNewRevision ($value=TRUE)
 
 isNewRevision ()
 
 isDefaultRevision ($new_value=NULL)
 
 isRevisionTranslationAffected ()
 
 setRevisionTranslationAffected ($affected)
 
 isDefaultTranslation ()
 
 getRevisionId ()
 
 isTranslatable ()
 
 preSave (EntityStorageInterface $storage)
 
 preSaveRevision (EntityStorageInterface $storage, \stdClass $record)
 
 validate ()
 
 isValidationRequired ()
 
 setValidationRequired ($required)
 
 __sleep ()
 
 id ()
 
 bundle ()
 
 uuid ()
 
 hasField ($field_name)
 
 get ($field_name)
 
 set ($name, $value, $notify=TRUE)
 
 getFields ($include_computed=TRUE)
 
 getTranslatableFields ($include_computed=TRUE)
 
 getIterator ()
 
 getFieldDefinition ($name)
 
 getFieldDefinitions ()
 
 toArray ()
 
 access ($operation, AccountInterface $account=NULL, $return_as_object=FALSE)
 
 language ()
 
 onChange ($name)
 
 getTranslation ($langcode)
 
 getUntranslated ()
 
 hasTranslation ($langcode)
 
 isNewTranslation ()
 
 removeTranslation ($langcode)
 
 getTranslationLanguages ($include_default=TRUE)
 
 updateOriginalValues ()
 
__get ($name)
 
 __set ($name, $value)
 
 __isset ($name)
 
 __unset ($name)
 
 createDuplicate ()
 
 __clone ()
 
 label ()
 
 referencedEntities ()
 
- Public Member Functions inherited from Entity
 __construct (array $values, $entity_type)
 
 id ()
 
 uuid ()
 
 isNew ()
 
 enforceIsNew ($value=TRUE)
 
 getEntityTypeId ()
 
 bundle ()
 
 label ()
 
 urlInfo ($rel='canonical', array $options=[])
 
 toUrl ($rel='canonical', array $options=[])
 
 hasLinkTemplate ($rel)
 
 link ($text=NULL, $rel='canonical', array $options=[])
 
 toLink ($text=NULL, $rel='canonical', array $options=[])
 
 url ($rel='canonical', $options=array())
 
 uriRelationships ()
 
 access ($operation, AccountInterface $account=NULL, $return_as_object=FALSE)
 
 language ()
 
 save ()
 
 delete ()
 
 createDuplicate ()
 
 getEntityType ()
 
 preSave (EntityStorageInterface $storage)
 
 postSave (EntityStorageInterface $storage, $update=TRUE)
 
 postCreate (EntityStorageInterface $storage)
 
 referencedEntities ()
 
 getCacheContexts ()
 
 getCacheTagsToInvalidate ()
 
 getCacheTags ()
 
 getCacheMaxAge ()
 
 getOriginalId ()
 
 setOriginalId ($id)
 
 toArray ()
 
 getTypedData ()
 
 __sleep ()
 
 getConfigDependencyKey ()
 
 getConfigDependencyName ()
 
 getConfigTarget ()
 
- Public Member Functions inherited from RefinableCacheableDependencyInterface
 addCacheContexts (array $cache_contexts)
 
 addCacheTags (array $cache_tags)
 
 mergeCacheMaxAge ($max_age)
 
 addCacheableDependency ($other_object)
 
- Public Member Functions inherited from ContentEntityInterface
 hasTranslationChanges ()
 
- Public Member Functions inherited from TranslatableInterface
 addTranslation ($langcode, array $values=array())
 
- Public Member Functions inherited from EntityChangedInterface
 getChangedTime ()
 
 setChangedTime ($timestamp)
 
 getChangedTimeAcrossTranslations ()
 

Static Public Member Functions

static postDelete (EntityStorageInterface $storage, array $entities)
 
static getAnonymousUser ()
 
static getAllowedTimezones ()
 
static getAllowedConfigurableLanguageCodes ()
 
- Static Public Member Functions inherited from ContentEntityBase
static baseFieldDefinitions (EntityTypeInterface $entity_type)
 
static bundleFieldDefinitions (EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
 
- Static Public Member Functions inherited from Entity
static preCreate (EntityStorageInterface $storage, array &$values)
 
static preDelete (EntityStorageInterface $storage, array $entities)
 
static postDelete (EntityStorageInterface $storage, array $entities)
 
static postLoad (EntityStorageInterface $storage, array &$entities)
 
static load ($id)
 
static loadMultiple (array $ids=NULL)
 
static create (array $values=array())
 

Protected Member Functions

 getRoleStorage ()
 
- Protected Member Functions inherited from ContentEntityBase
 getLanguages ()
 
 clearTranslationCache ()
 
 getTranslatedField ($name, $langcode)
 
 setDefaultLangcode ()
 
 updateFieldLangcodes ($langcode)
 
 initializeTranslation ($langcode)
 
 getEntityKey ($key)
 
- Protected Member Functions inherited from Entity
 entityManager ()
 
 entityTypeManager ()
 
 languageManager ()
 
 uuidGenerator ()
 
 linkTemplates ()
 
 urlRouteParameters ($rel)
 
 invalidateTagsOnSave ($update)
 

Static Protected Attributes

static $anonymousUser
 

Additional Inherited Members

- Data Fields inherited from ContentEntityBase
const TRANSLATION_REMOVED = 0
 
const TRANSLATION_EXISTING = 1
 
const TRANSLATION_CREATED = 2
 
- Static Protected Member Functions inherited from Entity
static invalidateTagsOnDelete (EntityTypeInterface $entity_type, array $entities)
 
- Protected Attributes inherited from ContentEntityBase
 $values = array()
 
 $fields = array()
 
 $fieldDefinitions
 
 $languages
 
 $langcodeKey
 
 $defaultLangcodeKey
 
 $activeLangcode = LanguageInterface::LANGCODE_DEFAULT
 
 $defaultLangcode
 
 $translations = array()
 
 $translationInitialize = FALSE
 
 $newRevision = FALSE
 
 $isDefaultRevision = TRUE
 
 $entityKeys = array()
 
 $translatableEntityKeys = array()
 
 $validated = FALSE
 
 $validationRequired = FALSE
 
- Protected Attributes inherited from Entity
 $entityTypeId
 
 $enforceIsNew
 
 $typedData
 

Detailed Description

Defines the user entity class.

The base table name here is plural, despite Drupal table naming standards, because "user" is a reserved word in many databases.

( id = "user", label = ("User"), handlers = { "storage" = "Drupal\user\UserStorage", "storage_schema" = "Drupal\user\UserStorageSchema", "access" = "Drupal\user\UserAccessControlHandler", "list_builder" = "Drupal\user\UserListBuilder", "views_data" = "Drupal\user\UserViewsData", "route_provider" = { "html" = "Drupal\user\Entity\UserRouteProvider", }, "form" = { "default" = "Drupal\user\ProfileForm", "cancel" = "Drupal\user\Form\UserCancelForm", "register" = "Drupal\user\RegisterForm" }, "translation" = "Drupal\user\ProfileTranslationHandler" }, admin_permission = "administer users", base_table = "users", data_table = "users_field_data", label_callback = "user_format_name", translatable = TRUE, entity_keys = { "id" = "uid", "langcode" = "langcode", "uuid" = "uuid" }, links = { "canonical" = "/user/{user}", "edit-form" = "/user/{user}/edit", "cancel-form" = "/user/{user}/cancel", "collection" = "/admin/people", }, field_ui_base_route = "entity.user.admin_form", common_reference_target = TRUE )

Definition at line 59 of file User.php.

Member Function Documentation

◆ activate()

activate ( )

{Activates the user.

Returns
The called user entity.
}

Implements UserInterface.

Definition at line 288 of file User.php.

◆ addRole()

addRole (   $rid)

{Add a role to a user.

Parameters
string$ridThe role ID to add.
}

Implements UserInterface.

Definition at line 174 of file User.php.

◆ block()

block ( )

{Blocks the user.

Returns
The called user entity.
}

Implements UserInterface.

Definition at line 296 of file User.php.

◆ checkExistingPassword()

checkExistingPassword ( UserInterface  $account_unchanged)

{Checks the existing password if set.

Parameters
\Drupal\user\UserInterface$account_unchangedThe unchanged user entity to compare against.
Returns
bool TRUE if the correct existing password was provided.
See also
UserInterface::setExistingPassword()
}

Implements UserInterface.

Definition at line 397 of file User.php.

◆ getAccountName()

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

Implements AccountInterface.

Definition at line 366 of file User.php.

◆ getAllowedConfigurableLanguageCodes()

static getAllowedConfigurableLanguageCodes ( )
static

Defines allowed configurable language codes for AllowedValues constraints.

Returns
string[] The allowed values.

Definition at line 566 of file User.php.

◆ getAllowedTimezones()

static getAllowedTimezones ( )
static

Defines allowed timezones for the field's AllowedValues constraint.

Returns
string[] The allowed values.

Definition at line 556 of file User.php.

◆ getAnonymousUser()

static getAnonymousUser ( )
static

Returns an anonymous user entity.

Returns
An anonymous user entity.

Definition at line 407 of file User.php.

◆ getCreatedTime()

getCreatedTime ( )

{Returns the creation time of the user as a UNIX timestamp.

Returns
int Timestamp of the creation date.
}

Implements UserInterface.

Definition at line 237 of file User.php.

◆ getDisplayName()

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

Implements AccountInterface.

Definition at line 373 of file User.php.

◆ getEmail()

getEmail ( )

{Returns the email address of this account.

Returns
string The email address.
}

Implements AccountInterface.

Definition at line 222 of file User.php.

◆ getInitialEmail()

getInitialEmail ( )

{Returns the email that was used when the user was registered.

Returns
string Initial email address of the user.
}

Implements UserInterface.

Definition at line 339 of file User.php.

◆ getLastAccessedTime()

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

Implements AccountInterface.

Definition at line 244 of file User.php.

◆ getLastLoginTime()

getLastLoginTime ( )

{Returns the UNIX timestamp when the user last logged in.

Returns
int Timestamp of the last login time.
}

Implements UserInterface.

Definition at line 259 of file User.php.

◆ getPassword()

getPassword ( )

{Returns the hashed password.

Returns
string The hashed password.
}

Implements UserInterface.

Definition at line 207 of file User.php.

◆ getPreferredAdminLangcode()

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

Implements AccountInterface.

Definition at line 325 of file User.php.

◆ getPreferredLangcode()

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

Implements AccountInterface.

Definition at line 311 of file User.php.

◆ getRoles()

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

Implements AccountInterface.

Definition at line 142 of file User.php.

◆ getRoleStorage()

getRoleStorage ( )
protected

Returns the role storage object.

Returns
The role storage object.

Definition at line 546 of file User.php.

◆ getTimeZone()

getTimeZone ( )

{Returns the timezone of this account.

Returns
string Name of the timezone.
}

Implements AccountInterface.

Definition at line 304 of file User.php.

◆ getUsername()

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 log in. 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.
}

Implements AccountInterface.

Definition at line 359 of file User.php.

◆ hasPermission()

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

Implements AccountInterface.

Definition at line 195 of file User.php.

◆ hasRole()

hasRole (   $rid)

{Whether a user has a certain role.

Parameters
string$ridThe role ID to check.
Returns
bool Returns TRUE if the user has the role, otherwise FALSE.
}

Implements UserInterface.

Definition at line 167 of file User.php.

◆ isActive()

isActive ( )

{Returns TRUE if the user is active.

Returns
bool TRUE if the user is active, false otherwise.
}

Implements UserInterface.

Definition at line 274 of file User.php.

◆ isAnonymous()

isAnonymous ( )

{Returns TRUE if the account is anonymous.

Returns
bool TRUE if the account is anonymous.
}

Implements AccountInterface.

Definition at line 352 of file User.php.

◆ isAuthenticated()

isAuthenticated ( )

{Returns TRUE if the account is authenticated.

Returns
bool TRUE if the account is authenticated.
}

Implements AccountInterface.

Definition at line 346 of file User.php.

◆ isBlocked()

isBlocked ( )

{Returns TRUE if the user is blocked.

Returns
bool TRUE if the user is blocked, false otherwise.
}

Implements UserInterface.

Definition at line 281 of file User.php.

◆ isNew()

isNew ( )

{Determines whether the entity is new.Usually an entity is new if no ID exists for it yet. However, entities may be enforced to be new with existing IDs too.

Returns
bool TRUE if the entity is new, or FALSE if the entity has already been saved.
See also
::enforceIsNew()
}

Implements EntityInterface.

Definition at line 73 of file User.php.

◆ postDelete()

static postDelete ( EntityStorageInterface  $storage,
array  $entities 
)
static

{Acts on deleted entities before the delete hook is invoked.Used after the entities are deleted but before invoking the delete hook.

Parameters
\Drupal\Core\Entity\EntityStorageInterface$storageThe entity storage object.
}

Implements EntityInterface.

Definition at line 132 of file User.php.

◆ postSave()

postSave ( EntityStorageInterface  $storage,
  $update = TRUE 
)

{Acts on a saved entity before the insert or update hook is invoked.Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters
\Drupal\Core\Entity\EntityStorageInterface$storageThe entity storage object.
bool$updateTRUE if the entity has been updated, or FALSE if it has been inserted.
}

Implements EntityInterface.

Definition at line 101 of file User.php.

◆ preSave()

preSave ( EntityStorageInterface  $storage)

{Acts on an entity before the presave hook is invoked.Used before the entity is saved and before invoking the presave hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed. This is different from its counterpart in the Field API, FieldItemListInterface::preSave(), which is fired on all field translations automatically.

Todo:
Adjust existing implementations and the documentation according to https://www.drupal.org/node/2577609 to have a consistent API.
Parameters
\Drupal\Core\Entity\EntityStorageInterface$storageThe entity storage object.
See also
::preSave()
Exceptions
}

Implements EntityInterface.

Definition at line 80 of file User.php.

◆ removeRole()

removeRole (   $rid)

{Remove a role from a user.

Parameters
string$ridThe role ID to remove.
}

Implements UserInterface.

Definition at line 188 of file User.php.

◆ setEmail()

setEmail (   $mail)

{Sets the email address of the user.

Parameters
string$mailThe new email address of the user.
Returns
The called user entity.
}

Implements UserInterface.

Definition at line 229 of file User.php.

◆ setExistingPassword()

setExistingPassword (   $password)

{Sets the existing plain text password.Required for validation when changing the password, name or email fields.

Parameters
string$passwordThe existing plain text password of the user.
Returns
$this
}

Implements UserInterface.

Definition at line 390 of file User.php.

◆ setLastAccessTime()

setLastAccessTime (   $timestamp)

{Sets the UNIX timestamp when the user last accessed the site..

Parameters
int$timestampTimestamp of the last access.
Returns
The called user entity.
}

Implements UserInterface.

Definition at line 251 of file User.php.

◆ setLastLoginTime()

setLastLoginTime (   $timestamp)

{Sets the UNIX timestamp when the user last logged in.

Parameters
int$timestampTimestamp of the last login time.
Returns
The called user entity.
}

Implements UserInterface.

Definition at line 266 of file User.php.

◆ setPassword()

setPassword (   $password)

{Sets the user password.

Parameters
string$passwordThe new unhashed password.
Returns
The called user entity.
}

Implements UserInterface.

Definition at line 214 of file User.php.

◆ setUsername()

setUsername (   $username)

{Sets the username of this account.

Parameters
string$usernameThe new user name.
Returns
The called user entity.
}

Implements UserInterface.

Definition at line 382 of file User.php.

Field Documentation

◆ $anonymousUser

$anonymousUser
staticprotected

Definition at line 68 of file User.php.


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