New XB pages also create a new revision on publish even though they are intended not to

Created on 11 July 2025, 4 days ago

Overview

Discovered in πŸ› Page revisions are missing information about author Active

The problem is in \Drupal\experience_builder\Controller\ApiAutoSaveController::post()

$use_existing_revision_id = AutoSaveManager::contentEntityIsConsideredNew($entity);

        if ($entity instanceof EntityPublishedInterface) {
          $entity->setPublished();
        }
        // If the entity is new, the autosaved data is considered to be part
        // of the first revision. Therefore, do not create a new revision
        // for new entities.
        if ($use_existing_revision_id) {
          $entity->setNewRevision(FALSE);
        }
        else {
          // Reset the revision ID.
          $entity->setNewRevision();
          $revision_id_key = $entity_definition->getKey('revision');
          \assert(\is_string($revision_id_key));
          $entity->set($revision_id_key, NULL);
        }

there are 2 problems with this

  1. $use_existing_revision_id = AutoSaveManager::contentEntityIsConsideredNew($entity);

    Because contentEntityIsConsideredNew() determines this by the title it will never return true unless the title was unchanged from when it was started. I believe intention here is that if the first time an entity is created in XB there should only be 1 revision after the first publish.

    So to fix that think we would want

    $use_existing_revision_id = AutoSaveManager::contentEntityIsConsideredNew($originalEntity);

    We already have $originalEntity at this point

  2. Even if you fix the problem above or if you actually don't change the title so a page is "Untitled page" setting

    $use_existing_revision_id = TRUE does not actually result in a new revision not being created.

    Debugging I can see that even though $entity->setNewRevision(FALSE); is called when publishing a page a new revision is always created.

    This is somewhat related to πŸ› Page revisions are missing information about author Active because this means the old revision will always be made by anonymous user.

Proposed resolution

  1. change $use_existing_revision_id = AutoSaveManager::contentEntityIsConsideredNew($originalEntity); so that this doesn't only return true when the title has remained unchanged before publishing the first time
  2. Figure out why $entity->setNewRevision(FALSE); still results in a new revision when publishing

User interface changes

There should be only 1 revision, by the publishing user, when a XB page is published

πŸ› Bug report
Status

Active

Version

0.0

Component

Auto-save

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

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

Comments & Activities

Production build 0.71.5 2024