add civility in user docgen normalizer

This commit is contained in:
Julien Fastré 2022-05-27 16:34:14 +02:00
parent 7278a5f3fa
commit 3c8b2207c4

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Civility;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
@ -60,9 +61,14 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
$context,
['docgen:expects' => Location::class, 'groups' => 'docgen:read']
);
$civilityContext = array_merge(
$context,
['docgen:expects' => Civility::class, 'groups' => 'docgen:read']
);
if (null === $user && 'docgen' === $format) {
return array_merge(self::NULL_USER, [
'civility' => $this->normalizer->normalize(null, $format, $civilityContext),
'user_job' => $this->normalizer->normalize(null, $format, $userJobContext),
'main_center' => $this->normalizer->normalize(null, $format, $centerContext),
'main_scope' => $this->normalizer->normalize(null, $format, $scopeContext),
@ -84,6 +90,7 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
];
if ('docgen' === $format) {
$data['civility'] = $this->normalizer->normalize($user->getCivility(), $format, $civilityContext);
$data['current_location'] = $this->normalizer->normalize($user->getCurrentLocation(), $format, $locationContext);
$data['main_location'] = $this->normalizer->normalize($user->getMainLocation(), $format, $locationContext);
}