From 4af7b1447590ae75ee13f42d5ebb64b90abd8308 Mon Sep 17 00:00:00 2001 From: vagrant Date: Thu, 5 Jun 2014 20:14:04 +0000 Subject: [PATCH] =?UTF-8?q?Issue=20#2074255=20by=20wiifm,=20JeroenT,=20Jalan?= =?UTF-8?q?dhar,=20G=C3=A1bor=20Hojtsy:=20Add=20changed=20time=20tracking=20?= =?UTF-8?q?to=20users.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/modules/user/src/Entity/User.php | 11 +++++ core/modules/user/src/UserInterface.php | 3 +- core/modules/user/user.install | 6 +++ core/modules/user/user.views.inc | 68 +++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index 6c0fb85..1fe27b7 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -441,6 +441,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')) @@ -528,6 +535,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 that the user was last edited.')); + // @todo Convert this to entity_reference_field, see // https://drupal.org/node/2044859. $fields['roles'] = FieldDefinition::create('string') diff --git a/core/modules/user/src/UserInterface.php b/core/modules/user/src/UserInterface.php index 4022179..ae4caaf 100644 --- a/core/modules/user/src/UserInterface.php +++ b/core/modules/user/src/UserInterface.php @@ -7,13 +7,14 @@ namespace Drupal\user; +use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Session\AccountInterface; /** * Provides an interface defining a user entity. */ -interface UserInterface extends ContentEntityInterface, AccountInterface { +interface UserInterface extends ContentEntityInterface, EntityChangedInterface, AccountInterface { /** * Whether a user has a certain role. diff --git a/core/modules/user/user.install b/core/modules/user/user.install index e0658c5..2d42c4b 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -46,6 +46,12 @@ function user_schema() { 'unsigned' => TRUE, 'default' => 0, ), + 'changed' => array( + 'description' => 'The Unix timestamp when the user was most recently saved.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), ), 'primary key' => array('uid', 'module', 'name'), 'indexes' => array( diff --git a/core/modules/user/user.views.inc b/core/modules/user/user.views.inc index 44c1cb3..a1b9f58 100644 --- a/core/modules/user/user.views.inc +++ b/core/modules/user/user.views.inc @@ -267,6 +267,74 @@ function user_views_data() { ), ); + $data['users']['changed'] = array( + 'title' => t('Updated date'), + 'help' => t('The date the user was last updated.'), + 'field' => array( + 'id' => 'date', + ), + 'sort' => array( + 'id' => 'date' + ), + 'filter' => array( + 'id' => 'date', + ), + ); + + $data['users']['changed_fulldate'] = array( + 'title' => t('Updated date'), + 'help' => t('Date in the form of CCYYMMDD.'), + 'argument' => array( + 'field' => 'changed', + 'id' => 'date_fulldate', + ), + ); + + $data['users']['changed_year_month'] = array( + 'title' => t('Updated year + month'), + 'help' => t('Date in the form of YYYYMM.'), + 'argument' => array( + 'field' => 'changed', + 'id' => 'date_year_month', + ), + ); + + $data['users']['changed_year'] = array( + 'title' => t('Updated year'), + 'help' => t('Date in the form of YYYY.'), + 'argument' => array( + 'field' => 'changed', + 'id' => 'date_year', + ), + ); + + $data['users']['changed_month'] = array( + 'title' => t('Updated month'), + 'help' => t('Date in the form of MM (01 - 12).'), + 'argument' => array( + 'field' => 'changed', + 'id' => 'date_month', + ), + ); + + $data['users']['changed_day'] = array( + 'title' => t('Updated day'), + 'help' => t('Date in the form of DD (01 - 31).'), + 'argument' => array( + 'field' => 'changed', + 'id' => 'date_day', + ), + ); + + $data['users']['changed_week'] = array( + 'title' => t('Updated week'), + 'help' => t('Date in the form of WW (01 - 53).'), + 'argument' => array( + 'field' => 'changed', + 'id' => 'date_week', + ), + ); + if (\Drupal::moduleHandler()->moduleExists('filter')) { $data['users']['signature'] = array( 'title' => t('Signature'), -- 1.7.9.5