diff --git a/core/modules/workspaces/src/EntityTypeInfo.php b/core/modules/workspaces/src/EntityTypeInfo.php index 55083bdc590..f1c71408df7 100644 --- a/core/modules/workspaces/src/EntityTypeInfo.php +++ b/core/modules/workspaces/src/EntityTypeInfo.php @@ -62,6 +62,12 @@ class EntityTypeInfo implements ContainerInjectionInterface { } } + // The 'file' entity type is allowed to perform CRUD operations inside a + // workspace without being tracked. + if ($entity_type->id() === 'file') { + $entity_type->setHandlerClass('workspace', IgnoredWorkspaceHandler::class); + } + // Internal entity types are allowed to perform CRUD operations inside a // workspace. if ($entity_type->isInternal()) { diff --git a/core/modules/workspaces/tests/modules/workspaces_test/workspaces_test.module b/core/modules/workspaces/tests/modules/workspaces_test/workspaces_test.module new file mode 100644 index 00000000000..27eef7c5c84 --- /dev/null +++ b/core/modules/workspaces/tests/modules/workspaces_test/workspaces_test.module @@ -0,0 +1,19 @@ + $entity_type) { + $entity_types[$entity_type_id] = $state->get("$entity_type_id.entity_type", $entity_types[$entity_type_id]); + } +} diff --git a/core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php b/core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php index 0fd6c43b45a..a6e99937ff5 100644 --- a/core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php +++ b/core/modules/workspaces/tests/src/Kernel/WorkspaceTestTrait.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\workspaces\Kernel; +use Drupal\workspaces\Entity\Handler\IgnoredWorkspaceHandler; use Drupal\workspaces\Entity\Workspace; /** @@ -140,4 +141,17 @@ trait WorkspaceTestTrait { return $query->execute(); } + /** + * Marks an entity type as ignored in a workspace. + * + * @param string $entity_type_id + * The entity type ID. + */ + protected function ignoreEntityType(string $entity_type_id): void { + $entity_type = clone \Drupal::entityTypeManager()->getDefinition($entity_type_id); + $entity_type->setHandlerClass('workspace', IgnoredWorkspaceHandler::class); + \Drupal::state()->set("$entity_type_id.entity_type", $entity_type); + \Drupal::entityTypeManager()->clearCachedDefinitions(); + } + } diff --git a/core/modules/workspaces/tests/src/Kernel/WorkspacesFileItemTest.php b/core/modules/workspaces/tests/src/Kernel/WorkspacesFileItemTest.php new file mode 100644 index 00000000000..eee017f9bd6 --- /dev/null +++ b/core/modules/workspaces/tests/src/Kernel/WorkspacesFileItemTest.php @@ -0,0 +1,65 @@ +entityTypeManager = \Drupal::entityTypeManager(); + + $this->installEntitySchema('workspace'); + $this->installSchema('workspaces', ['workspace_association']); + + // Create a new workspace and activate it. + Workspace::create(['id' => 'stage', 'label' => 'Stage'])->save(); + $this->switchToWorkspace('stage'); + } + + /** + * {@inheritdoc} + */ + public function testFileItem(): void { + // Ignore entity types that are not being tested, in order to fully re-use + // the parent test method. + $this->ignoreEntityType('entity_test'); + $this->ignoreEntityType('entity_view_display'); + + parent::testFileItem(); + } + +}