Skip to content
Snippets Groups Projects

Fix double-revision saving in a workspace.

1 unresolved thread
3 files
+ 31
14
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -182,20 +182,18 @@ public function entityInsert(EntityInterface $entity) {
$this->workspaceAssociation->trackEntity($entity, $this->workspaceManager->getActiveWorkspace());
// When an entity is newly created in a workspace, it should be published in
// that workspace, but not yet published on the live workspace. It is first
// saved as unpublished for the default revision, then immediately a second
// revision is created which is published and attached to the workspace.
// This ensures that the published version of the entity does not 'leak'
// into the live site. This differs from edits to existing entities where
// there is already a valid default revision for the live workspace.
// When a published entity is created in a workspace, it should remain
// published only in that workspace, and unpublished in the live workspace.
// It is first saved as unpublished for the default revision, then
// immediately a second revision is created which is published and attached
// to the workspace. This ensures that the initial version of the entity
// does not 'leak' into the live site. This differs from edits to existing
// entities where there is already a valid default revision for the live
// workspace.
if (isset($entity->_initialPublished)) {
// Operate on a clone to avoid changing the entity prior to subsequent
// hook_entity_insert() implementations.
$pending_revision = clone $entity;
$pending_revision->setPublished();
$pending_revision->isDefaultRevision(FALSE);
$pending_revision->save();
$entity->setPublished();
$entity->isDefaultRevision(FALSE);
$entity->save();
}
}
Loading