diff --git a/src/Bundle/ChillMainBundle/Entity/UserJob.php b/src/Bundle/ChillMainBundle/Entity/UserJob.php index 5f0bea45d..99db5d4f1 100644 --- a/src/Bundle/ChillMainBundle/Entity/UserJob.php +++ b/src/Bundle/ChillMainBundle/Entity/UserJob.php @@ -40,6 +40,7 @@ class UserJob * @var array|string[]A * @ORM\Column(name="label", type="json") * @Serializer\Groups({"read", "docgen:read"}) + * @Serializer\Context({"is-translatable": true}, groups={"docgen:read"}) */ protected array $label = []; diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php index 3562c1361..677199ad4 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php @@ -16,10 +16,11 @@ use libphonenumber\PhoneNumber; use libphonenumber\PhoneNumberUtil; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Serializer\Exception\UnexpectedValueException; +use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -class PhonenumberNormalizer implements NormalizerInterface, DenormalizerInterface +class PhonenumberNormalizer implements ContextAwareNormalizerInterface, DenormalizerInterface { private string $defaultCarrierCode; @@ -53,6 +54,10 @@ class PhonenumberNormalizer implements NormalizerInterface, DenormalizerInterfac public function normalize($object, ?string $format = null, array $context = []): string { + if ($format === 'docgen' && null === $object) { + return ''; + } + return $this->phoneNumberUtil->formatOutOfCountryCallingNumber($object, $this->defaultCarrierCode); } @@ -61,8 +66,18 @@ class PhonenumberNormalizer implements NormalizerInterface, DenormalizerInterfac return 'libphonenumber\PhoneNumber' === $type; } - public function supportsNormalization($data, ?string $format = null) + public function supportsNormalization($data, ?string $format = null, array $context = []): bool { - return $data instanceof PhoneNumber; + if ($data instanceof PhoneNumber && $format === 'json') { + return true; + } + + if ($format === 'docgen' && ( + $data instanceof PhoneNumber || PhoneNumber::class === ($context['docgen:expects'] ?? null) + )) { + return true; + } + + return false; } }