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.
Comments
Database keys are usually in the revision base table
The database keys (
revision_uid,revision_timestamp, andrevision_login 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_revisionandnode_field_revisiontaxonomy_term_revisionandtaxonomy_term_field_revision