2021-06-21 13:38:43 +02:00

46 lines
1.3 KiB
PHP

<?php
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
class SocialActionNormalizer implements NormalizerInterface, NormalizerAwareInterface
{
use NormalizerAwareTrait;
private SocialActionRender $render;
public function __construct(SocialActionRender $render)
{
$this->render = $render;
}
/**
* {@inheritDoc}
*/
public function normalize($socialAction, string $format = null, array $context = [])
{
return [
'id' => $socialAction->getId(),
'type' => 'social_work_social_action',
'text' => $this->render->renderString($socialAction, []),
'parent' => $this->normalizer->normalize($socialAction->getParent()),
'desactivationDate' => $this->normalizer->normalize($socialAction->getDesactivationDate()),
'title' => $socialAction->getTitle()
];
}
/**
* {@inheritDoc}
*/
public function supportsNormalization($data, string $format = null)
{
return $data instanceof SocialAction;
}
}