Delete entity revision does not delete from field_data table

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;   } 
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Delete entity revision does not delete from field_data table

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.