Entity revisions

In Drupal 8, all content entity types can be made revisionable (and publishable) with minimal effort. Since Node is such an example, we can check out how it's built to understand this better.

First, the annotation needs to have the database table information where revisions are stored. This mirrors exactly the original tables we saw before:

revision_table = "node_revision",
revision_data_table = "node_field_revision",

Second, the annotation needs to have the entity keys for the revision ID and the published status we saw earlier:

*   entity_keys = { 
*     "revision" = "vid", 
*     "published" = "status", 
*   }, 

Third, also in the annotation, the revision metadata keys need to be referenced:

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

These map to table columns in the revision table. And in order to ensure that all the necessary columns get created, the entity type class should extend from EditorialContentEntityBase which provides the necessary field definitions for this. But good to know also that this base class already implements the EntityPublishedInterface which allows to make the entity type publishable.

Finally, the entity fields themselves are not automatically revisionable so a flag needs to be also set on them. Again, we will see that in a minute when we talk about the fields.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset