Change record status: 
Project: 
Introduced in branch: 
8.4.x
Introduced in version: 
8.4.0-beta1
Description: 

The revision metadata fields are now defined in the entity annotation and ContentEntityTypeInterface has three new methods for dealing with the revision metadata fields:

  • ContentEntityTypeInterface::getRevisionMetadataKeys() - returns all the revision metadata field names keyed by the revision metadata key
  • ContentEntityTypeInterface::getRevisionMetadataKey() - returns the revision metadata field name for the given revision metadata key
  • ContentEntityTypeInterface::hasRevisionMetadataKey() - check if a revision metadata field is defined for the given revision metadata key

ContentEntityTypeInterface::getRevisionMetadataKeys has a parameter for backwards compatibility to search for the revision metadata field names through the base field definitions but as of Drupal 9.0.0 it will be removed and the revision metadata keys will have to be explicitly defined in the entity annotation.

The three revision metadata keys we have currently in core are:

  • revision_created
  • revision_user
  • revision_log_message

And an example for defining the revision metadata keys in the entity annotation could be retrieved from the Node entity:

 *   revision_metadata_keys = {
 *     "revision_user" = "revision_uid",
 *     "revision_created" = "revision_timestamp",
 *     "revision_log_message" = "revision_log",
 *   },

However the default annotation is typically:

 *   revision_metadata_keys = {
 *     "revision_user" = "revision_user",
 *     "revision_created" = "revision_created",
 *     "revision_log_message" = "revision_log_message",
 *   },

See documentation on how to convert a content entity type to be revisionable.

Impacts: 
Module developers

Comments

benjifisher’s picture

The database keys (revision_uid, revision_timestamp, and revision_log in the example snippet) are usually (always?) fields on the revision base table. I lost some time looking for them on the revision data table.

If the fields are already present in the database, then you just need to update the annotations in the entity class. Most of the documentation page "how to convert a content entity type to be revisionable" explains how to update the database tables.

For example, the revision base table and the revision data table are

  • Node: node_revision and node_field_revision
  • Taxonomy term: taxonomy_term_revision and taxonomy_term_field_revision