From b8a7cbb3218392a088b96d8c003a3af08fd839a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 19 Sep 2025 10:40:41 +0200 Subject: [PATCH] Add `identifiers` field in `CreationPersonType` and handle `on_create` logic in `PersonIdentifiersType` - Introduce `identifiers` field to `CreationPersonType` with a dedicated form type. - Update `PersonIdentifiersType` to support `step` option (`on_create` and `on_edit`). - Skip certain identifiers in `on_create` step based on presence configuration. - Adjust Twig template to display `identifiers` conditionally. --- .../ChillPersonBundle/Form/CreationPersonType.php | 5 +++++ .../Form/PersonIdentifiersType.php | 14 ++++++++++++++ .../Resources/views/Person/create.html.twig | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php index bb40c6c35..83e811eac 100644 --- a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php @@ -89,6 +89,11 @@ final class CreationPersonType extends AbstractType 'label' => false, ]); + $builder->add('identifiers', PersonIdentifiersType::class, [ + 'by_reference' => false, + 'step' => 'on_create', + ]); + if ($this->askCenters) { $builder ->add('center', PickCenterType::class, [ diff --git a/src/Bundle/ChillPersonBundle/Form/PersonIdentifiersType.php b/src/Bundle/ChillPersonBundle/Form/PersonIdentifiersType.php index ea077f626..0ab057280 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonIdentifiersType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonIdentifiersType.php @@ -12,10 +12,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Form; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Chill\PersonBundle\Entity\Identifier\IdentifierPresenceEnum; use Chill\PersonBundle\Form\DataMapper\PersonIdentifiersDataMapper; use Chill\PersonBundle\PersonIdentifier\PersonIdentifierManagerInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; final class PersonIdentifiersType extends AbstractType { @@ -32,6 +34,12 @@ final class PersonIdentifiersType extends AbstractType continue; } + // skip some on creation + if ('on_create' === $options['step'] + && IdentifierPresenceEnum::ON_EDIT === $worker->getDefinition()->getPresence()) { + continue; + } + $subBuilder = $builder->create( 'identifier_'.$worker->getDefinition()->getId(), options: [ @@ -45,4 +53,10 @@ final class PersonIdentifiersType extends AbstractType $builder->setDataMapper($this->identifiersDataMapper); } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefault('step', 'on_edit') + ->setAllowedValues('step', ['on_edit', 'on_create']); + } } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig index 1ceb84395..5a17acf18 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig @@ -88,6 +88,15 @@
{% endfor %} {% endif %} + {% if form.identifiers|length > 0 %} + {% for f in form.identifiers %} +
+ {{ form_row(f) }} +
+ {% endfor %} + {% else %} + {{ form_widget(form.identifiers) }} + {% endif %} {{ form_row(form.gender, { 'label' : 'Gender'|trans }) }}