class User

Defines the user entity class.

Plugin annotation


@EntityType(
  id = "user",
  label = @Translation("User"),
  module = "user",
  controllers = {
    "storage" = "Drupal\user\UserStorageController",
    "access" = "Drupal\user\UserAccessController",
    "render" = "Drupal\Core\Entity\EntityRenderController",
    "form" = {
      "profile" = "Drupal\user\ProfileFormController",
      "register" = "Drupal\user\RegisterFormController"
    },
    "translation" = "Drupal\user\ProfileTranslationController"
  },
  default_operation = "profile",
  base_table = "users",
  uri_callback = "user_uri",
  route_base_path = "admin/config/people/accounts",
  label_callback = "user_label",
  fieldable = TRUE,
  translatable = TRUE,
  entity_keys = {
    "id" = "uid",
    "uuid" = "uuid"
  },
  links = {
    "canonical" = "/user/{user}",
    "edit-form" = "/user/{user}/edit"
  }
)

Hierarchy

Expanded class hierarchy of User

3 files declare their use of User
RoleAccessCheckTest.php in drupal/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTest.php
Contains \Drupal\Tests\Core\Route\RoleAccessCheckTest.
user.module in drupal/core/modules/user/user.module
Enables the user registration and login system.
UserEntityTest.php in drupal/core/modules/user/lib/Drupal/user/Tests/UserEntityTest.php
Contains \Drupal\user\Tests\UserEntityTest.
46 string references to 'User'
AddRoleUserTest::getInfo in drupal/core/modules/user/tests/Drupal/user/Tests/Plugin/Action/AddRoleUserTest.php
This method exists to support the simpletest UI runner.
BreadcrumbTest::testBreadCrumbs in drupal/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
Tests breadcrumbs on node and administrative paths.
contact_field_extra_fields in drupal/core/modules/contact/contact.module
Implements hook_field_extra_fields().
DbLogController::overview in drupal/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php
Displays a listing of database log messages.
dblog_event in drupal/core/modules/dblog/dblog.admin.inc
Page callback: Displays details about a specific database log message.

... See full list

File

drupal/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php, line 51
Definition of Drupal\user\Plugin\Core\Entity\User.

Namespace

Drupal\user\Plugin\Core\Entity
View source
class User extends EntityNG implements UserInterface {

  /**
   * The user ID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $uid;

  /**
   * The user UUID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $uuid;

  /**
   * The unique user name.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $name;

  /**
   * The user's password (hashed).
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $pass;

  /**
   * The user's email address.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $mail;

  /**
   * The user's default theme.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $theme;

  /**
   * The user's signature.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $signature;

  /**
   * The user's signature format.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $signature_format;

  /**
   * The timestamp when the user was created.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $created;

  /**
   * The timestamp when the user last accessed the site. A value of 0 means the
   * user has never accessed the site.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $access;

  /**
   * The timestamp when the user last logged in. A value of 0 means the user has
   * never logged in.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $login;

  /**
   * Whether the user is active (1) or blocked (0).
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $status;

  /**
   * The user's timezone.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $timezone;

  /**
   * The user's langcode.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $langcode;

  /**
   * The user's preferred langcode for receiving emails and viewing the site.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $preferred_langcode;

  /**
   * The user's preferred langcode for viewing administration pages.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $preferred_admin_langcode;

  /**
   * The email address used for initial account creation.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $init;

  /**
   * The user's roles.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $roles;

  /**
   * The plain data values of the contained properties.
   *
   * Define default values.
   *
   * @var array
   */
  protected $values = array(
    'langcode' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => Language::LANGCODE_NOT_SPECIFIED,
        ),
      ),
    ),
    'preferred_langcode' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => Language::LANGCODE_NOT_SPECIFIED,
        ),
      ),
    ),
    'admin_preffered_langcode' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => Language::LANGCODE_NOT_SPECIFIED,
        ),
      ),
    ),
    'name' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => '',
        ),
      ),
    ),
    'mail' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => '',
        ),
      ),
    ),
    'init' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => '',
        ),
      ),
    ),
    'access' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => 0,
        ),
      ),
    ),
    'login' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => 0,
        ),
      ),
    ),
    'status' => array(
      Language::LANGCODE_DEFAULT => array(
        0 => array(
          'value' => 1,
        ),
      ),
    ),
  );

  /**
   * {@inheritdoc}
   */
  public function id() {
    return $this
      ->get('uid')->value;
  }

  /**
   * {@inheritdoc}
   */
  protected function init() {
    parent::init();
    unset($this->access);
    unset($this->created);
    unset($this->init);
    unset($this->login);
    unset($this->mail);
    unset($this->name);
    unset($this->pass);
    unset($this->preferred_admin_langcode);
    unset($this->preferred_langcode);
    unset($this->roles);
    unset($this->signature);
    unset($this->signature_format);
    unset($this->status);
    unset($this->theme);
    unset($this->timezone);
    unset($this->uid);
    unset($this->uuid);
  }

  /**
   * {@inheritdoc}
   */
  public function getBCEntity() {
    if (!isset($this->bcEntity)) {

      // Initialize field definitions so that we can pass them by reference.
      $this
        ->getPropertyDefinitions();
      $this->bcEntity = new UserBCDecorator($this, $this->fieldDefinitions);
    }
    return $this->bcEntity;
  }

  /**
   * {@inheritdoc}
   */
  public function getRoles() {
    $roles = array();
    foreach ($this
      ->get('roles') as $role) {
      $roles[] = $role->value;
    }
    return $roles;
  }

  /**
   * {@inheritdoc}
   */
  public function getSecureSessionId() {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getSessionData() {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getSessionId() {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function hasRole($rid) {
    return in_array($rid, $this
      ->getRoles());
  }

  /**
   * {@inheritdoc}
   */
  public function addRole($rid) {
    $roles = $this
      ->getRoles();
    $roles[] = $rid;
    $this
      ->set('roles', array_unique($roles));
  }

  /**
   * {@inheritdoc}
   */
  public function removeRole($rid) {
    $this
      ->set('roles', array_diff($this
      ->getRoles(), array(
      $rid,
    )));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
Entity::$entityType protected property The entity type.
Entity::$isDefaultRevision protected property Indicates whether this is the default revision. 1
Entity::$newRevision protected property Boolean indicating whether a new revision should be created on save.
Entity::access public function Implements \Drupal\Core\TypedData\AccessibleInterface::access(). Overrides AccessibleInterface::access
Entity::delete public function Implements \Drupal\Core\Entity\EntityInterface::delete(). Overrides EntityInterface::delete 3
Entity::enforceIsNew public function Implements \Drupal\Core\Entity\EntityInterface::enforceIsNew(). Overrides EntityInterface::enforceIsNew
Entity::entityInfo public function Implements \Drupal\Core\Entity\EntityInterface::entityInfo(). Overrides EntityInterface::entityInfo
Entity::entityType public function Implements \Drupal\Core\Entity\EntityInterface::entityType(). Overrides EntityInterface::entityType
Entity::getConstraints public function Implements \Drupal\Core\TypedData\TypedDataInterface::getConstraints(). Overrides TypedDataInterface::getConstraints
Entity::getDefinition public function Implements \Drupal\Core\TypedData\TypedDataInterface::getDefinition(). Overrides TypedDataInterface::getDefinition
Entity::getExportProperties public function Implements \Drupal\Core\Entity\EntityInterface::getExportProperties(). Overrides EntityInterface::getExportProperties 1
Entity::getName public function Implements \Drupal\Core\TypedData\TypedDataInterface::getName(). Overrides TypedDataInterface::getName
Entity::getNGEntity public function Implements \Drupal\Core\Entity\EntityInterface::getNGEntity(). Overrides EntityInterface::getNGEntity
Entity::getParent public function Implements \Drupal\Core\TypedData\TypedDataInterface::getParent(). Overrides TypedDataInterface::getParent
Entity::getPropertyPath public function Implements \Drupal\Core\TypedData\TypedDataInterface::getPropertyPath(). Overrides TypedDataInterface::getPropertyPath
Entity::getRevisionId public function Implements \Drupal\Core\Entity\EntityInterface::getRevisionId(). Overrides EntityInterface::getRevisionId 4
Entity::getRoot public function Implements \Drupal\Core\TypedData\TypedDataInterface::getRoot(). Overrides TypedDataInterface::getRoot
Entity::getString public function Implements \Drupal\Core\TypedData\TypedDataInterface::getString(). Overrides TypedDataInterface::getString
Entity::getValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::getValue(). Overrides TypedDataInterface::getValue
Entity::isDefaultRevision public function Implements \Drupal\Core\Entity\EntityInterface::isDefaultRevision(). Overrides EntityInterface::isDefaultRevision 1
Entity::isNew public function Implements \Drupal\Core\Entity\EntityInterface::isNew(). Overrides EntityInterface::isNew 1
Entity::isNewRevision public function Implements \Drupal\Core\Entity\EntityInterface::isNewRevision(). Overrides EntityInterface::isNewRevision
Entity::isTranslatable public function Implements \Drupal\Core\Entity\EntityInterface::isTranslatable(). Overrides EntityInterface::isTranslatable
Entity::onChange public function Implements \Drupal\Core\TypedData\ComplexDataInterface::onChange(). Overrides ComplexDataInterface::onChange
Entity::save public function Implements \Drupal\Core\Entity\EntityInterface::save(). Overrides EntityInterface::save 6
Entity::setContext public function Implements \Drupal\Core\TypedData\TypedDataInterface::setContext(). Overrides TypedDataInterface::setContext
Entity::setNewRevision public function Implements \Drupal\Core\Entity\EntityInterface::setNewRevision(). Overrides EntityInterface::setNewRevision
Entity::setValue public function Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). Overrides TypedDataInterface::setValue
Entity::uriRelationships public function Returns a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityNG::$bcEntity protected property An instance of the backward compatibility decorator.
EntityNG::$bundle protected property Local cache holding the value of the bundle field.
EntityNG::$fieldDefinitions protected property Local cache for field definitions.
EntityNG::$fields protected property The array of fields, each being an instance of FieldInterface.
EntityNG::$uriPlaceholderReplacements protected property Local cache for URI placeholder substitution values.
EntityNG::bundle public function Implements \Drupal\Core\Entity\EntityInterface::bundle(). Overrides Entity::bundle
EntityNG::createDuplicate public function Overrides Entity::createDuplicate(). Overrides Entity::createDuplicate 1
EntityNG::get public function Implements \Drupal\Core\TypedData\ComplexDataInterface::get(). Overrides Entity::get
EntityNG::getIterator public function Implements \IteratorAggregate::getIterator(). Overrides Entity::getIterator
EntityNG::getProperties public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getProperties(). Overrides Entity::getProperties
EntityNG::getPropertyDefinition public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinition(). Overrides Entity::getPropertyDefinition
EntityNG::getPropertyDefinitions public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). Overrides Entity::getPropertyDefinitions
EntityNG::getPropertyValues public function Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyValues(). Overrides Entity::getPropertyValues
EntityNG::getTranslatedField protected function Gets a translated field.
EntityNG::getTranslation public function Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslation(). Overrides Entity::getTranslation
EntityNG::getTranslationLanguages public function Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages(). Overrides Entity::getTranslationLanguages
EntityNG::getType public function Gets the typed data type of the entity. Overrides Entity::getType
EntityNG::isEmpty public function Implements \Drupal\Core\TypedData\ComplexDataInterface::isEmpty(). Overrides Entity::isEmpty
EntityNG::label public function Overrides Entity::label() to access the label field with the new API. Overrides Entity::label 3
EntityNG::language public function Implements \Drupal\Core\TypedData\TranslatableInterface::language(). Overrides Entity::language
EntityNG::set public function Implements \Drupal\Core\TypedData\ComplexDataInterface::set(). Overrides Entity::set
EntityNG::setPropertyValues public function Implements \Drupal\Core\TypedData\ComplexDataInterface::setPropertyValues(). Overrides Entity::setPropertyValues
EntityNG::translations public function Overrides Entity::translations(). Overrides Entity::translations
EntityNG::updateOriginalValues public function Updates the original values with the interim changes.
EntityNG::uri public function Implements \Drupal\Core\Entity\EntityInterface::uri(). Overrides Entity::uri 1
EntityNG::uriPlaceholderReplacements protected function Returns an array of placeholders for this entity.
EntityNG::uuid public function Overrides Entity::uuid(). Overrides Entity::uuid
EntityNG::validate public function Implements \Drupal\Core\TypedData\TypedDataInterface::validate(). Overrides Entity::validate
EntityNG::__clone public function Magic method: Implements a deep clone.
EntityNG::__construct public function Overrides Entity::__construct(). Overrides Entity::__construct
EntityNG::__get public function Implements the magic method for setting object properties.
EntityNG::__isset public function Implements the magic method for isset().
EntityNG::__set public function Implements the magic method for setting object properties.
EntityNG::__unset public function Implements the magic method for unset.
EntityNG::__wakeup public function Magic __wakeup() implementation.
User::$access public property The timestamp when the user last accessed the site. A value of 0 means the user has never accessed the site.
User::$created public property The timestamp when the user was created.
User::$init public property The email address used for initial account creation.
User::$langcode public property The user's langcode. Overrides Entity::$langcode
User::$login public property The timestamp when the user last logged in. A value of 0 means the user has never logged in.
User::$mail public property The user's email address.
User::$name public property The unique user name.
User::$pass public property The user's password (hashed).
User::$preferred_admin_langcode public property The user's preferred langcode for viewing administration pages.
User::$preferred_langcode public property The user's preferred langcode for receiving emails and viewing the site.
User::$roles public property The user's roles.
User::$signature public property The user's signature.
User::$signature_format public property The user's signature format.
User::$status public property Whether the user is active (1) or blocked (0).
User::$theme public property The user's default theme.
User::$timezone public property The user's timezone.
User::$uid public property The user ID.
User::$uuid public property The user UUID.
User::$values protected property The plain data values of the contained properties. Overrides EntityNG::$values
User::addRole public function Add a role to a user. Overrides UserInterface::addRole
User::getBCEntity public function Overrides Entity::getBCEntity(). Overrides EntityNG::getBCEntity
User::getRoles public function Returns a list of roles. Overrides UserInterface::getRoles
User::getSecureSessionId public function Returns the secure session ID. Overrides AccountInterface::getSecureSessionId
User::getSessionData public function Returns the session data. Overrides AccountInterface::getSessionData
User::getSessionId public function Returns the session ID. Overrides AccountInterface::getSessionId
User::hasRole public function Whether a user has a certain role. Overrides UserInterface::hasRole
User::id public function Implements \Drupal\Core\Entity\EntityInterface::id(). Overrides EntityNG::id
User::init protected function Initialize the object. Invoked upon construction and wake up. Overrides EntityNG::init
User::removeRole public function Remove a role from a user. Overrides UserInterface::removeRole