/** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\Core\Entity\EntityPublishedInterface $entity */
if (!
$entity->
isNew() && !
$entity->
isSyncing()) { // Force a new revision if the entity is not replicating.
$entity->
setNewRevision(TRUE
);
// All entities in the non-default workspace are pending revisions,
// regardless of their publishing status. This means that when creating
// a published pending revision in a non-default workspace it will also be
// a published pending revision in the default workspace, however, it will
// become the default revision only when it is replicated to the default
// workspace.
$entity->
isDefaultRevision(FALSE
);
} // Track the workspaces in which the new revision was saved.
if (!
$entity->
isSyncing()) { $field_name =
$entity_type->
getRevisionMetadataKey('workspace'
);
$entity->
{$field_name}->target_id =
$this->workspaceManager->
getActiveWorkspace()->
id();
} // When a new published entity is inserted in a non-default workspace, we
// actually want two revisions to be saved:
// - An unpublished default revision in the default ('live') workspace.