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..749e690 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( @@ -386,3 +392,17 @@ function taxonomy_update_8007() { } } } + +/** + * Add a changed column for taxonomy terms. + */ +function taxonomy_update_8008() { + $spec = array( + 'description' => 'The Unix timestamp when the term was most recently saved.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + 'initial' => REQUEST_TIME, + ); + db_add_field('taxonomy_term_data', 'changed', $spec); +}