I created a custom entity, I can edit, save, delete, create revisions and revert. I adapted the code from node module to achieve all this and everything works just fine except the revision deletion.
This code will delete entries from my_entity_revision
table but not from my_entity_revision_field_data
table:
$this->myEntityStorage->deleteRevision($revision_id)
Any ideas why this might happen? Thanks.
Here is my entity annotation:
@ContentEntityType( id = "my_entity", label = @Translation("My entity"), bundle_label = @Translation("My Entity type"), handlers = { "list_builder" = "Drupalmy_entityControllerMyEntityListBuilder", "view_builder" = "DrupalCoreEntityEntityViewBuilder", "access" = "Drupalwebsite_settingsMyEntityAccessControlHandler", "form" = { "default" = "Drupalmy_entityFormMyEntityForm", "add" = "Drupalmy_entityFormMyEntityForm", "edit" = "Drupalmy_entityFormMyEntityForm", "delete" = "Drupalmy_entityFormMyEntityDeleteForm" }, "views_data" = "Drupalmy_entityMyEntityViewsData", }, base_table = "my_entity", data_table = "my_entity_field_data", revision_table = "my_entity_revision", revision_data_table = "my_entity_revision_field_data", translatable = TRUE, entity_revision_parent_id_field = "parent_id", entity_keys = { "id" = "id", "uuid" = "uuid", "bundle" = "type", "langcode" = "langcode", "revision" = "revision_id" }, bundle_entity_type = "my_entity_type", field_ui_base_route = "entity.my_entity_type.edit_form", links = { "canonical" = "/admin/structure/my_entity/{my_entity}", "edit-form" = "/admin/structure/my_entity/{my_entity}/edit", "delete-form" = "/admin/structure/my_entity/{my_entity}/delete", "revision" = "/admin/structure/my_entity/{my_entity}/revision/{my_entity_revision}/view", "version-history" = "/admin/structure/my_entity/{my_entity}/revisions" } )
And my baseFieldDefinition:
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { // Standard field, used as unique if primary index. $fields['id'] = BaseFieldDefinition::create('integer') ->setLabel(t('ID')) ->setDescription(t('The ID of the Website settings entity.')) ->setReadOnly(TRUE); // Standard field, unique outside of the scope of the current project. $fields['uuid'] = BaseFieldDefinition::create('uuid') ->setLabel(t('UUID')) ->setDescription(t('The UUID of the Website settings entity.')) ->setReadOnly(TRUE); $fields['revision_id'] = BaseFieldDefinition::create('integer') ->setLabel(t('Revision ID')) ->setDescription(t('The paragraphs entity revision ID.')) ->setReadOnly(TRUE) ->setSetting('unsigned', TRUE); $fields['type'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Type')) ->setDescription(t('The website settings bundle type.')) ->setSetting('target_type', 'website_settings_type') ->setReadOnly(TRUE); $fields['langcode'] = BaseFieldDefinition::create('language') ->setLabel(t('Language code')) ->setDescription(t('The paragraphs entity language code.')) ->setRevisionable(TRUE); $fields['uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Authored by')) ->setDescription(t('The user ID of the website settings author.')) ->setRevisionable(TRUE) ->setSetting('target_type', 'user') ->setSetting('handler', 'default') ->setDefaultValueCallback('Drupalwebsite_settingsEntityWebsiteSettings::getCurrentUserId') ->setTranslatable(TRUE) ->setDisplayOptions('view', array( 'label' => 'hidden', 'type' => 'hidden', 'weight' => 0, )) ->setDisplayOptions('form', array( 'type' => 'hidden', 'weight' => 0, )) ->setDisplayConfigurable('view', TRUE) ->setDisplayConfigurable('form', TRUE); // We set display options for the view as well as the form. // Users with correct privileges can change the view and edit configuration. $fields['title'] = BaseFieldDefinition::create('string') ->setLabel(t('Title')) ->setSettings(array( 'default_value' => '', 'max_length' => 255, 'text_processing' => 0, )) ->setDisplayOptions('view', array( 'label' => 'above', 'type' => 'string', 'weight' => -6, )) ->setDisplayOptions('form', array( 'type' => 'string_textfield', 'weight' => -6, )) ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); $fields['status'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Published')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setDefaultValue(TRUE) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Authored on')) ->setDescription(t('The time that the website settings was created.')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setDisplayOptions('view', array( 'type' => 'hidden', 'weight' => 0, )) ->setDisplayOptions('form', array( 'type' => 'hidden', 'weight' => 0, )) ->setDisplayConfigurable('view', TRUE) ->setDisplayConfigurable('form', TRUE); $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed on')) ->setDescription(t('The time that the website settings was last updated.')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setDisplayOptions('view', array( 'type' => 'hidden', 'weight' => 0, )) ->setDisplayOptions('form', array( 'type' => 'hidden', 'weight' => 0, )) ->setDisplayConfigurable('view', TRUE) ->setDisplayConfigurable('form', TRUE); $fields['revision_uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Revision user ID')) ->setDescription(t('The user ID of the author of the current revision.')) ->setSetting('target_type', 'user') ->setQueryable(FALSE) ->setRevisionable(TRUE); $fields['parent_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Parent ID')) ->setDescription(t('The ID of the parent entity of which this entity is referenced.')) ->setSetting('target_type', 'my_entity') ->setSetting('handler', 'default') ->setRevisionable(TRUE); $fields['langcode'] = BaseFieldDefinition::create('language') ->setLabel(t('Language code')) ->setDescription(t('The language code of ContentEntityExample entity.')); return $fields; }