Drupal 8  8.0.2
User Class Reference
Inheritance diagram for User:

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 baseFieldDefinitions (EntityTypeInterface $entity_type)
 
static getAllowedTimezones ()
 
static getAllowedConfigurableLanguageCodes ()
 
- Static Public Member Functions inherited from ContentEntityBase
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 )

Member Function Documentation

activate ( )

{Activates the user.

Returns
The called user entity.
}

Implements UserInterface.

addRole (   $rid)

{Add a role to a user.

Parameters
string$ridThe role ID to add.
}

Implements UserInterface.

References RoleInterface\ANONYMOUS_ID, RoleInterface\AUTHENTICATED_ID, User\getRoles(), and ContentEntityBase\set().

Here is the call graph for this function:

static baseFieldDefinitions ( EntityTypeInterface  $entity_type)
static

{Provides base field definitions for an entity type.Implementations typically use the class for creating the field definitions; for example a 'name' field could be defined as the following:

$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'));
By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use ::bundleFieldDefinitions().The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.
Parameters
\Drupal\Core\Entity\EntityTypeInterface$entity_typeThe entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.
Returns
[] An array of base field definitions for the entity type, keyed by field name.
See Also
::getFieldDefinitions()
::bundleFieldDefinitions()
}

Implements FieldableEntityInterface.

References FieldStorageDefinitionInterface\CARDINALITY_UNLIMITED, BaseFieldDefinition\create(), and t().

Here is the call graph for this function:

block ( )

{Blocks the user.

Returns
The called user entity.
}

Implements UserInterface.

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.

References UserInterface\getPassword(), and Drupal\service().

Here is the call graph for this function:

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.

Referenced by User\getDisplayName(), and User\getUsername().

Here is the caller graph for this function:

static getAllowedConfigurableLanguageCodes ( )
static

Defines allowed configurable language codes for AllowedValues constraints.

Returns
string[] The allowed values.

References ContentEntityBase\getLanguages(), Drupal\languageManager(), and LanguageInterface\STATE_CONFIGURABLE.

Here is the call graph for this function:

static getAllowedTimezones ( )
static

Defines allowed timezones for the field's AllowedValues constraint.

Returns
string[] The allowed values.

Referenced by FieldFieldTest\setUp().

Here is the caller graph for this function:

static getAnonymousUser ( )
static

Returns an anonymous user entity.

Returns
An anonymous user entity.

References Drupal\entityManager(), and LanguageInterface\LANGCODE_DEFAULT.

Referenced by DbLogController\eventDetails(), Comment\getOwner(), and UserCancelTest\testUserAnonymize().

Here is the call graph for this function:

Here is the caller graph for this function:

getCreatedTime ( )

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

Returns
int Timestamp of the creation date.
}

Implements UserInterface.

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.

References Drupal\config(), User\getAccountName(), and Drupal\moduleHandler().

Here is the call graph for this function:

getEmail ( )

{Returns the email address of this account.

Returns
string The email address.
}

Implements AccountInterface.

getInitialEmail ( )

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

Returns
string Initial email address of the user.
}

Implements UserInterface.

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.

getLastLoginTime ( )

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

Returns
int Timestamp of the last login time.
}

Implements UserInterface.

getPassword ( )

{Returns the hashed password.

Returns
string The hashed password.
}

Implements UserInterface.

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.

References Entity\languageManager().

Here is the call graph for this function:

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.

References Entity\languageManager().

Here is the call graph for this function:

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.

References RoleInterface\ANONYMOUS_ID, RoleInterface\AUTHENTICATED_ID, and User\isAuthenticated().

Referenced by User\addRole(), User\hasPermission(), User\hasRole(), and User\removeRole().

Here is the call graph for this function:

Here is the caller graph for this function:

getRoleStorage ( )
protected

Returns the role storage object.

Returns
The role storage object.

Referenced by User\hasPermission().

Here is the caller graph for this function:

getTimeZone ( )

{Returns the timezone of this account.

Returns
string Name of the timezone.
}

Implements AccountInterface.

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

Implements AccountInterface.

References User\getAccountName().

Here is the call 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.
}

Implements AccountInterface.

References User\getRoles(), and User\getRoleStorage().

Here is the call graph for this function:

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.

References User\getRoles().

Here is the call graph for this function:

isActive ( )

{Returns TRUE if the user is active.

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

Implements UserInterface.

isAnonymous ( )

{Returns TRUE if the account is anonymous.

Returns
bool TRUE if the account is anonymous.
}

Implements AccountInterface.

References ContentEntityBase\id().

Here is the call graph for this function:

isAuthenticated ( )

{Returns TRUE if the account is authenticated.

Returns
bool TRUE if the account is authenticated.
}

Implements AccountInterface.

References ContentEntityBase\id().

Referenced by User\getRoles().

Here is the call graph for this function:

Here is the caller graph for this function:

isBlocked ( )

{Returns TRUE if the user is blocked.

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

Implements UserInterface.

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.

References Entity\enforceIsNew(), and ContentEntityBase\id().

Here is the call graph for this function:

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.
\Drupal\Core\Entity\EntityInterface[]$entities An array of entities.
}

Implements EntityInterface.

References Drupal\service().

Here is the call graph for this function:

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.

References Drupal\currentUser(), and Drupal\service().

Here is the call graph for this function:

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

Implements EntityInterface.

References RoleInterface\ANONYMOUS_ID, RoleInterface\AUTHENTICATED_ID, and Drupal\service().

Here is the call graph for this function:

removeRole (   $rid)

{Remove a role from a user.

Parameters
string$ridThe role ID to remove.
}

Implements UserInterface.

References User\getRoles(), and ContentEntityBase\set().

Here is the call graph for this function:

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.

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.

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.

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.

setPassword (   $password)

{Sets the user password.

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

Implements UserInterface.

setUsername (   $username)

{Sets the username of this account.

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

Implements UserInterface.

References ContentEntityBase\set().

Here is the call graph for this function:


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