Issue #3025785 by amateescu, mallezie, s_leu, smustgrave, tim.plunkett: Cannot create entity with image in a workspace
(cherry picked from commit 4229a611e5
)
merge-requests/6829/merge
parent
081b69b53e
commit
36465e605c
|
@ -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()) {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides supporting code for testing workspaces.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_entity_type_alter().
|
||||
*/
|
||||
function workspaces_test_entity_type_alter(array &$entity_types) {
|
||||
$state = \Drupal::state();
|
||||
|
||||
// Allow all entity types to have their definition changed dynamically for
|
||||
// testing purposes.
|
||||
foreach ($entity_types as $entity_type_id => $entity_type) {
|
||||
$entity_types[$entity_type_id] = $state->get("$entity_type_id.entity_type", $entity_types[$entity_type_id]);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\workspaces\Kernel;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Tests\file\Kernel\FileItemTest;
|
||||
use Drupal\Tests\user\Traits\UserCreationTrait;
|
||||
use Drupal\workspaces\Entity\Workspace;
|
||||
|
||||
/**
|
||||
* Tests using entity fields of the file field type in a workspace.
|
||||
*
|
||||
* @group workspaces
|
||||
*/
|
||||
class WorkspacesFileItemTest extends FileItemTest {
|
||||
|
||||
use UserCreationTrait;
|
||||
use WorkspaceTestTrait;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*/
|
||||
protected EntityTypeManagerInterface $entityTypeManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = [
|
||||
'file',
|
||||
'path_alias',
|
||||
'workspaces',
|
||||
'workspaces_test',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue