Skip to content
Snippets Groups Projects
Commit 86b2f9e2 authored by catch's avatar catch
Browse files

Issue #3498115 by amateescu: Fix usage of temporary entity data in Workspaces

parent 017ad48a
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
*/ */
class EntityOperations { class EntityOperations {
/**
* A list of entity UUIDs that were created as published in a workspace.
*/
protected array $initialPublished = [];
public function __construct( public function __construct(
protected EntityTypeManagerInterface $entityTypeManager, protected EntityTypeManagerInterface $entityTypeManager,
protected WorkspaceManagerInterface $workspaceManager, protected WorkspaceManagerInterface $workspaceManager,
...@@ -113,11 +118,9 @@ public function entityPresave(EntityInterface $entity): void { ...@@ -113,11 +118,9 @@ public function entityPresave(EntityInterface $entity): void {
// - An unpublished default revision in the default ('live') workspace. // - An unpublished default revision in the default ('live') workspace.
// - A published pending revision in the current workspace. // - A published pending revision in the current workspace.
if ($entity->isNew() && $entity->isPublished()) { if ($entity->isNew() && $entity->isPublished()) {
// Keep track of the publishing status in a dynamic property for // Keep track of the initially published entities for ::entityInsert(),
// ::entityInsert(), then unpublish the default revision. // then unpublish the default revision.
// @todo Remove this dynamic property once we have an API for associating $this->initialPublished[$entity->uuid()] = TRUE;
// temporary data with an entity: https://www.drupal.org/node/2896474.
$entity->_initialPublished = TRUE;
$entity->setUnpublished(); $entity->setUnpublished();
} }
} }
...@@ -147,7 +150,7 @@ public function entityInsert(EntityInterface $entity): void { ...@@ -147,7 +150,7 @@ public function entityInsert(EntityInterface $entity): void {
// does not 'leak' into the live site. This differs from edits to existing // 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 // entities where there is already a valid default revision for the live
// workspace. // workspace.
if (isset($entity->_initialPublished)) { if (isset($this->initialPublished[$entity->uuid()])) {
// Ensure that the default revision of an entity saved in a workspace is // Ensure that the default revision of an entity saved in a workspace is
// unpublished. // unpublished.
if ($entity->isPublished()) { if ($entity->isPublished()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment