person: fix adding civility to a person with OnTheFly form

This commit is contained in:
nobohan 2022-04-14 21:37:16 +02:00
parent 7a2151f23a
commit 7d3239d6d6
2 changed files with 18 additions and 3 deletions

View File

@ -87,7 +87,7 @@
<label>{{ $t('person.gender.title') }}</label>
</div>
<div class="form-floating mb-3">
<div v-if="action === 'create'" class="form-floating mb-3">
<select
class="form-select form-select-lg"
id="civility"
@ -187,8 +187,8 @@ export default {
get() { return this.person.gender; }
},
civility: {
set(value) { this.person.civility = value; },
get() { return this.person.civility; }
set(value) { this.person.civility = {id: value}; },
get() { return this.person.civility ? this.person.civility.id : undefined; }
},
birthDate: {
set(value) {

View File

@ -12,7 +12,9 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Civility;
use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface;
use Chill\MainBundle\Repository\CivilityRepository;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
use Chill\PersonBundle\Entity\Person;
@ -54,6 +56,8 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
private PersonRepository $repository;
private CivilityRepository $civilityRepository;
private ResidentialAddressRepository $residentialAddressRepository;
public function __construct(
@ -61,12 +65,14 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
PersonRepository $repository,
CenterResolverManagerInterface $centerResolverManager,
ResidentialAddressRepository $residentialAddressRepository,
CivilityRepository $civilityRepository,
PhoneNumberHelperInterface $phoneNumberHelper /* TODO maybe not necessayr any more */
) {
$this->render = $render;
$this->repository = $repository;
$this->centerResolverManager = $centerResolverManager;
$this->residentialAddressRepository = $residentialAddressRepository;
$this->civilityRepository = $civilityRepository;
$this->phoneNumberHelper = $phoneNumberHelper;
}
@ -101,6 +107,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
'center',
'altNames',
'email',
'civility'
];
$fields = array_filter(
@ -176,6 +183,14 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
case 'email':
$person->setEmail($data[$item]);
break;
case 'civility':
//$civility = $this->denormalizer->denormalize($data[$item], Civility::class, $format, $context); // this seems the right way to do it, but this does not render a Civility object.
$civility = $this->civilityRepository->findOneBy(['id' => $data[$item]['id']]);
$person->setCivility($civility);
break;
}
}