22
33namespace App \Serializer \Normalizer ;
44
5- use ApiPlatform \Core \Api \OperationType ;
6- use ApiPlatform \Core \Api \UrlGeneratorInterface ;
7- use ApiPlatform \Core \Bridge \Symfony \Routing \RouteNameResolverInterface ;
85use App \Entity \ContentType ;
9- use Symfony \ Component \ Routing \ RouterInterface ;
6+ use App \ Metadata \ Resource \ Factory \ UriTemplateFactory ;
107use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
118use Symfony \Component \Serializer \SerializerAwareInterface ;
129use Symfony \Component \Serializer \SerializerInterface ;
1714class ContentTypeNormalizer implements NormalizerInterface, SerializerAwareInterface {
1815 public function __construct (
1916 private NormalizerInterface $ decorated ,
20- private RouteNameResolverInterface $ routeNameResolver ,
21- private RouterInterface $ router ,
17+ private UriTemplateFactory $ uriTemplateFactory ,
2218 ) {
2319 }
2420
@@ -30,7 +26,11 @@ public function normalize($object, $format = null, array $context = []) {
3026 $ data = $ this ->decorated ->normalize ($ object , $ format , $ context );
3127
3228 if ($ object instanceof ContentType && isset ($ data ['entityClass ' ])) {
33- $ data ['entityPath ' ] = $ this ->router ->generate ($ this ->routeNameResolver ->getRouteName ($ data ['entityClass ' ], OperationType::COLLECTION ), [], UrlGeneratorInterface::ABS_PATH );
29+ [$ uriTemplate , $ templated ] = $ this ->uriTemplateFactory ->createFromResourceClass ($ data ['entityClass ' ]);
30+ $ data ['_links ' ]['contentNodes ' ]['href ' ] = $ uriTemplate ;
31+ $ data ['_links ' ]['contentNodes ' ]['templated ' ] = $ templated ;
32+
33+ unset($ data ['entityClass ' ]);
3434 }
3535
3636 return $ data ;
0 commit comments