Entity Revisions not showing?

Created on 12 March 2024, about 1 year ago

Problem/Motivation

I have created a custom entity that is revisionable. If I edit an existing entity and check the box labeled "Create new revision," I expect to see a new revision.

Instead, I see "No revision." If I use drush sql-query "SELECT * from my_entity_revision;" I can see there are revisions being saved.

Steps to reproduce

Use drush generate entity:content to generate a new entity with the name "my_entity" and make sure to answer "Yes" when asked "Make the entity type revisionable? [No]:".

Add the following to the baseFieldDefinitions in my_entity.php

    $fields['first_name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('First Name'))
      ->setRevisionable(TRUE)
      ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'settings' => [
          'display_label' => TRUE,
        ],
      ])
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'string',
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setRequired(TRUE);

Save the file, use drush en my_entity to enable the new entity type.

Go to `/my_entity/add` and create a new entity. Save. Edit the entity, changing the first name, and check the box that says "Create new revision." Add some revision message. Save.

Edit the entity again - there are no revisions displayed.

Use drush sql-query "SELECT * from my_entity_revision;" to verify that a revision has been created in the database.

Proposed resolution

N/A

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

πŸ’¬ Support request
Status

Active

Version

10.1 ✨

Component
EntityΒ  β†’

Last updated about 9 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States _San_

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @_San_
  • πŸ‡·πŸ‡΄Romania bbu23

    Do you have show_revision_ui = TRUE in your annotation?

  • πŸ‡ΊπŸ‡ΈUnited States _San_

    @bbu23 - yes, I do have that annotation.

    I was able to make some progress by implementing the changes described here: https://www.drupal.org/node/3160443 β†’

    I am now able to see the revisions by going directly to /my_entity/{id}/revisions, but I'm still not seeing the revisions when I edit the entity.

  • πŸ‡ΊπŸ‡ΈUnited States _San_
  • πŸ‡·πŸ‡΄Romania bbu23

    Ah, so you're missing the tab? Do you have the MODULENAME.links.task.yml file, and do you have in the file something like this:
    entity.ENTITYTYPE.version_history:
    route_name: entity.ENTITYTYPE.version_history
    base_route: entity.ENTITYTYPE.canonical
    title: 'Revisions'
    weight: 20

    Though for that you might also need the route entity.ENTITYTYPE.version_history in MODULENAME.routing.yml unless it's already defined there or dynamically in an Html Route Provider.

  • πŸ‡ΊπŸ‡ΈUnited States _San_

    Progress!

  • πŸ‡ΊπŸ‡ΈUnited States _San_

    Here's a copy of my code.

  • Status changed to Closed: works as designed 3 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    It has been 10 month without discussion here. Perhaps this support query has been sorted out elsewhere?

    @_San_ , The Drupal Core issue queue is not the ideal place for support requests. There are several support options listed on our support page β†’ (Community > Support at the top of Drupal.org) and there is Drupal Slack β†’ . You may get better replies in one of those places.

    And Drupal 10.1 is out of security support, so I am closing this.

Production build 0.71.5 2024