2
2
3
3
namespace App \Serializer \Normalizer ;
4
4
5
- use ApiPlatform \Core \Api \OperationType ;
6
- use ApiPlatform \Core \Api \UrlGeneratorInterface ;
7
- use ApiPlatform \Core \Bridge \Symfony \Routing \RouteNameResolverInterface ;
8
5
use App \Entity \ContentType ;
9
- use Symfony \ Component \ Routing \ RouterInterface ;
6
+ use App \ Metadata \ Resource \ Factory \ UriTemplateFactory ;
10
7
use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
11
8
use Symfony \Component \Serializer \SerializerAwareInterface ;
12
9
use Symfony \Component \Serializer \SerializerInterface ;
17
14
class ContentTypeNormalizer implements NormalizerInterface, SerializerAwareInterface {
18
15
public function __construct (
19
16
private NormalizerInterface $ decorated ,
20
- private RouteNameResolverInterface $ routeNameResolver ,
21
- private RouterInterface $ router ,
17
+ private UriTemplateFactory $ uriTemplateFactory ,
22
18
) {
23
19
}
24
20
@@ -30,7 +26,11 @@ public function normalize($object, $format = null, array $context = []) {
30
26
$ data = $ this ->decorated ->normalize ($ object , $ format , $ context );
31
27
32
28
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 ' ]);
34
34
}
35
35
36
36
return $ data ;
0 commit comments