mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
normalization for docgen:read: add groups and so on (wip)
This commit is contained in:
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
@@ -30,18 +31,48 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte
|
||||
|
||||
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(),
|
||||
];
|
||||
switch ($format) {
|
||||
case 'json':
|
||||
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(),
|
||||
];
|
||||
case 'docgen':
|
||||
|
||||
if (null === $socialAction) {
|
||||
return ['id' => 0, 'title' => '', 'text' => ''];
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $socialAction->getId(),
|
||||
'text' => $this->render->renderString($socialAction, []),
|
||||
'title' => $socialAction->getTitle(),
|
||||
];
|
||||
default:
|
||||
throw new \Symfony\Component\Serializer\Exception\RuntimeException("format not supported");
|
||||
}
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null)
|
||||
public function supportsNormalization($data, string $format = null, array $context = [])
|
||||
{
|
||||
return $data instanceof SocialAction;
|
||||
if ($data instanceof SocialAction && 'json' === $format) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ('docgen' === $format) {
|
||||
if ($data instanceof SocialAction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (null === $data && ($context['docgen:expects'] ?? null) === SocialAction::class) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user