.../Tests/Upgrade/FilledStandardUpgradePathTest.php | 4 ++++ .../taxonomy/lib/Drupal/taxonomy/Entity/Term.php | 20 ++++++++++++++++++++ .../taxonomy/lib/Drupal/taxonomy/TermInterface.php | 8 ++++++++ core/modules/taxonomy/taxonomy.install | 6 ++++++ 4 files changed, 38 insertions(+) diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilledStandardUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilledStandardUpgradePathTest.php index 0064c4c..7457533 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilledStandardUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilledStandardUpgradePathTest.php @@ -106,6 +106,10 @@ public function testFilledStandardUpgrade() { $this->assertTrue(isset($entity_view_modes['full'])); } + // Ensure that taxonomy terms have a 'changed' timestamp. + $term = entity_load('taxonomy_term', 1); + $this->assertNotEqual($term->getChangedTime(), 0); + // Check that user data has been migrated correctly. $query = db_query('SELECT * FROM {users_data}'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php index daeb3ac..da83581 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php @@ -176,6 +176,14 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont /** * {@inheritdoc} */ + public function preSave(EntityStorageControllerInterface $storage_controller) { + // Before saving the term, set changed time. + $this->changed->value = REQUEST_TIME; + } + + /** + * {@inheritdoc} + */ public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) { // Only change the parents if a value is set, keep the existing values if // not. @@ -241,7 +249,19 @@ public static function baseFieldDefinitions($entity_type) { 'settings' => array('default_value' => 0), 'computed' => TRUE, ); + $properties['changed'] = array( + 'label' => t('Changed'), + 'description' => t('The time that the term was last edited.'), + 'type' => 'integer_field', + ); return $properties; } + /** + * {@inheritdoc} + */ + public function getChangedTime() { + return $this->changed->value; + } + } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php index f9bb432..fa4b4ca 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php @@ -14,4 +14,12 @@ */ interface TermInterface extends ContentEntityInterface { + /** + * Returns the term modification timestamp. + * + * @return int + * Term modification timestamp. + */ + public function getChangedTime(); + } diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 4d4c952..c214974 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -78,6 +78,12 @@ function taxonomy_schema() { 'default' => 0, 'description' => 'The weight of this term in relation to other terms.', ), + 'changed' => array( + 'description' => 'The Unix timestamp when the term was most recently saved.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), ), 'primary key' => array('tid'), 'unique keys' => array(