From 259cdd34c444dd96e88f4acac29dc9d27ae9cc41 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 25 Mar 2022 11:07:12 +0100 Subject: [PATCH] fix validation person resource --- .../Controller/PersonResourceController.php | 20 +++---------------- .../Entity/Person/PersonResource.php | 1 + .../Form/PersonResourceType.php | 4 ---- .../translations/validators.fr.yml | 1 + 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php index 004961594..6d35f8140 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php @@ -145,30 +145,16 @@ final class PersonResourceController extends AbstractController public function newAction(Request $request, $person_id) { $personOwner = $this->personRepository->find($person_id); + $personResource = new PersonResource(); + $personResource->setPersonOwner($personOwner); - $form = $this->createForm(PersonResourceType::class); + $form = $this->createForm(PersonResourceType::class, $personResource); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner); - $personResource = new PersonResource(); - - $person = $form['person']->getData(); - $thirdparty = $form['thirdparty']->getData(); - $freetext = $form['freetext']->getData(); - $comment = $form['comment']->getData(); - $kind = $form['kind']->getData(); - - $personResource->setKind($kind); - $personResource->setPerson($person); - $personResource->setThirdParty($thirdparty); - $personResource->setFreeText($freetext); - $personResource->setComment($comment); - - $personResource->setPersonOwner($personOwner); - $this->em->persist($personResource); $this->em->flush(); diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index b1022cf4c..73bd23106 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -232,6 +232,7 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface } if (null !== $this->person && $this->person === $this->personOwner) { + $context->buildViolation('You cannot associate a resource with the same person') ->addViolation(); } diff --git a/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php b/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php index 31af0a649..aeab09fea 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php @@ -29,12 +29,8 @@ use Symfony\Contracts\Translation\TranslatorInterface; final class PersonResourceType extends AbstractType { - private PersonRenderInterface $personRender; - private ResourceKindRender $resourceKindRender; - private ThirdPartyRender $thirdPartyRender; - private TranslatorInterface $translator; public function __construct(ResourceKindRender $resourceKindRender, PersonRenderInterface $personRender, ThirdPartyRender $thirdPartyRender, TranslatorInterface $translator) diff --git a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml index 452365c4c..492f50396 100644 --- a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml @@ -57,3 +57,4 @@ Only the referrer can change the confidentiality of a parcours: 'Seul le référ # resource You must associate at least one entity: Associez un usager, un tiers ou indiquez une description libre +You cannot associate a resource with the same person: Vous ne pouvez pas ajouter la personne elle-même en tant que ressource. \ No newline at end of file