entityTypeManager = $entity_type_manager; $this->workspaceManager = $workspace_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('entity_type.manager'), $container->get('workspaces.manager') ); } /** * Adds the "EntityWorkspaceConflict" constraint to eligible entity types. * * @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types * An associative array of all entity type definitions, keyed by the entity * type name. Passed by reference. * * @see hook_entity_type_build() */ public function entityTypeBuild(array &$entity_types) { foreach ($entity_types as $entity_type) { if ($this->workspaceManager->isEntityTypeSupported($entity_type)) { $entity_type->addConstraint('EntityWorkspaceConflict'); } } } /** * Alters field plugin definitions. * * @param array[] $definitions * An array of field plugin definitions. * * @see hook_field_info_alter() */ public function fieldInfoAlter(&$definitions) { if (isset($definitions['entity_reference'])) { $definitions['entity_reference']['constraints']['EntityReferenceSupportedNewEntities'] = []; } } }