2222use ApiPlatform \Metadata \Operation ;
2323use ApiPlatform \Metadata \Resource \Factory \ResourceMetadataCollectionFactoryInterface ;
2424use ApiPlatform \Metadata \Resource \ResourceMetadataCollection ;
25+ use ApiPlatform \State \Util \StateOptionsTrait ;
2526use Doctrine \ORM \EntityManagerInterface ;
2627use Doctrine \Persistence \ManagerRegistry ;
2728
2829final class DoctrineOrmResourceCollectionMetadataFactory implements ResourceMetadataCollectionFactoryInterface
2930{
31+ use StateOptionsTrait;
32+
3033 public function __construct (private readonly ManagerRegistry $ managerRegistry , private readonly ResourceMetadataCollectionFactoryInterface $ decorated )
3134 {
3235 }
@@ -45,10 +48,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
4548 if ($ operations ) {
4649 /** @var Operation $operation */
4750 foreach ($ resourceMetadata ->getOperations () as $ operationName => $ operation ) {
48- $ entityClass = $ operation ->getClass ();
49- if (($ options = $ operation ->getStateOptions ()) && $ options instanceof Options && $ options ->getEntityClass ()) {
50- $ entityClass = $ options ->getEntityClass ();
51- }
51+ $ entityClass = $ this ->getStateOptionsClass ($ operation , $ operation ->getClass (), Options::class);
5252
5353 if (!$ this ->managerRegistry ->getManagerForClass ($ entityClass ) instanceof EntityManagerInterface) {
5454 continue ;
@@ -64,10 +64,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
6464
6565 if ($ graphQlOperations ) {
6666 foreach ($ graphQlOperations as $ operationName => $ graphQlOperation ) {
67- $ entityClass = $ graphQlOperation ->getClass ();
68- if (($ options = $ graphQlOperation ->getStateOptions ()) && $ options instanceof Options && $ options ->getEntityClass ()) {
69- $ entityClass = $ options ->getEntityClass ();
70- }
67+ $ entityClass = $ this ->getStateOptionsClass ($ graphQlOperation , $ graphQlOperation ->getClass (), Options::class);
7168
7269 if (!$ this ->managerRegistry ->getManagerForClass ($ entityClass ) instanceof EntityManagerInterface) {
7370 continue ;
0 commit comments