diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php new file mode 100644 index 000000000..27e5b21f7 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php @@ -0,0 +1,56 @@ +security = $security; + } + + public function denormalize($data, string $type, ?string $format = null, array $context = []) + { + if (null === $data) { + return null; + } + + $comment = new PrivateCommentEmbeddable(); + + $comment->setCommentForUser($this->security->getUser(), $data['privateComment']); + } + + public function supportsDenormalization($data, string $type, ?string $format = null) + { + return $type === CommentEmbeddable::class; + } + + public function normalize($comment, $format = null, array $contect = []) + { + return $comment->getComment(); + } + + public function supportsNormalization($data, ?string $format = null) + { + return $data instanceof CommentEmbeddable; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/config/services/serializer.yaml b/src/Bundle/ChillMainBundle/config/services/serializer.yaml index 4d8aa9954..1084dab71 100644 --- a/src/Bundle/ChillMainBundle/config/services/serializer.yaml +++ b/src/Bundle/ChillMainBundle/config/services/serializer.yaml @@ -10,4 +10,7 @@ services: Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer: tags: - { name: 'serializer.normalizer', priority: 8 } + Chill\MainBundle\Serializer\Normalizer\PrivateCommentEmbeddableNormalizer: + autowire: true + autoconfigure: true