diff --git a/core/modules/user/lib/Drupal/user/Entity/User.php b/core/modules/user/lib/Drupal/user/Entity/User.php index 83e2103..22d98ac 100644 --- a/core/modules/user/lib/Drupal/user/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Entity/User.php @@ -114,6 +114,9 @@ public function preSave(EntityStorageInterface $storage) { \Drupal::service('user.data')->set('user', $this->id(), substr($key, 5), $this->{$key}); } } + + // Before saving the user, set changed time. + $this->changed->value = REQUEST_TIME; } /** @@ -445,6 +448,13 @@ public function setUsername($username) { /** * {@inheritdoc} */ + public function getChangedTime() { + return $this->get('changed')->value; + } + + /** + * {@inheritdoc} + */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['uid'] = FieldDefinition::create('integer') ->setLabel(t('User ID')) @@ -529,6 +539,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The email address used for initial account creation.')) ->setSetting('default_value', ''); + $fields['changed'] = FieldDefinition::create('changed') + ->setLabel(t('Changed')) + ->setDescription(t('The time the user was most recently saved.')); + // @todo Convert this to entity_reference_field, see // https://drupal.org/node/2044859. $fields['roles'] = FieldDefinition::create('string') diff --git a/core/modules/user/lib/Drupal/user/UserInterface.php b/core/modules/user/lib/Drupal/user/UserInterface.php index 4022179..68c2974 100644 --- a/core/modules/user/lib/Drupal/user/UserInterface.php +++ b/core/modules/user/lib/Drupal/user/UserInterface.php @@ -179,4 +179,11 @@ public function block(); */ public function getInitialEmail(); + /** + * Returns the user modification timestamp. + * + * @return int + * User modification timestamp. + */ + public function getChangedTime(); } diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 97515a2..421102e 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -123,6 +123,12 @@ function user_schema() { 'default' => '', 'description' => 'E-mail address used for initial account creation.', ), + 'changed' => array( + 'description' => 'The Unix timestamp when the user was most recently saved.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), ), 'indexes' => array( 'access' => array('access'),