Take null value for gender into account and user Interface for translatableStringHelper

This commit is contained in:
Julie Lenaerts 2024-11-26 15:37:05 +01:00
parent 0b22250dd5
commit f4f5153ed0
2 changed files with 3 additions and 3 deletions

View File

@ -12,7 +12,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
@ -21,7 +21,7 @@ class GenderDocGenNormalizer implements ContextAwareNormalizerInterface, Normali
{
use NormalizerAwareTrait;
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper) {}
public function __construct(private readonly TranslatableStringHelperInterface $translatableStringHelper) {}
public function supportsNormalization($data, ?string $format = null, array $context = [])
{

View File

@ -95,7 +95,7 @@ class PersonDocGenNormalizer implements
'age' => (int) $person->getAge(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $dateContext),
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $dateContext),
'gender' => $this->translatableStringHelper->localize($person->getGender()->getLabel()),
'gender' => null !== ($g = $person->getGender()) ? $this->translatableStringHelper->localize($g->getLabel()) : '',
'genderEntity' => $this->normalizer->normalize($person->getGender(), $format, $genderContext),
'maritalStatus' => null !== ($ms = $person->getMaritalStatus()) ? $this->translatableStringHelper->localize($ms->getName()) : '',
'maritalStatusDate' => $this->normalizer->normalize($person->getMaritalStatusDate(), $format, $dateContext),