3 namespace Drupal\workspaces;
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
10 * Manipulates entity type information.
12 * This class contains primarily bridged hooks for compile-time or
13 * cache-clear-time hooks. Runtime hooks should be placed in EntityOperations.
17 class EntityTypeInfo implements ContainerInjectionInterface {
20 * The entity type manager service.
22 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
24 protected $entityTypeManager;
27 * The workspace manager service.
29 * @var \Drupal\workspaces\WorkspaceManagerInterface
31 protected $workspaceManager;
34 * Constructs a new EntityTypeInfo instance.
36 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
37 * The entity type manager service.
38 * @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
39 * The workspace manager service.
41 public function __construct(EntityTypeManagerInterface $entity_type_manager, WorkspaceManagerInterface $workspace_manager) {
42 $this->entityTypeManager = $entity_type_manager;
43 $this->workspaceManager = $workspace_manager;
49 public static function create(ContainerInterface $container) {
51 $container->get('entity_type.manager'),
52 $container->get('workspaces.manager')
57 * Adds the "EntityWorkspaceConflict" constraint to eligible entity types.
59 * @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
60 * An associative array of all entity type definitions, keyed by the entity
61 * type name. Passed by reference.
63 * @see hook_entity_type_build()
65 public function entityTypeBuild(array &$entity_types) {
66 foreach ($entity_types as $entity_type) {
67 if ($this->workspaceManager->isEntityTypeSupported($entity_type)) {
68 $entity_type->addConstraint('EntityWorkspaceConflict');