From b26d0905a38a9885a28baa98ed7504860c55e214 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 21 Jan 2022 15:01:12 +0100 Subject: [PATCH 1/4] type variable added and file renamed in transformer --- ...erToJsonTransformer.php => EntityToJsonTransformer.php} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename src/Bundle/ChillMainBundle/Form/Type/DataTransformer/{UserToJsonTransformer.php => EntityToJsonTransformer.php} (92%) diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/UserToJsonTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php similarity index 92% rename from src/Bundle/ChillMainBundle/Form/Type/DataTransformer/UserToJsonTransformer.php rename to src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php index df670f891..969247908 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/UserToJsonTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php @@ -25,13 +25,16 @@ class UserToJsonTransformer implements DataTransformerInterface private bool $multiple; + private string $type; + private SerializerInterface $serializer; - public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, bool $multiple) + public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, bool $multiple, string $type) { $this->denormalizer = $denormalizer; $this->serializer = $serializer; $this->multiple = $multiple; + $this->type = $type; } public function reverseTransform($value) @@ -72,7 +75,7 @@ class UserToJsonTransformer implements DataTransformerInterface return $this->denormalizer->denormalize( - ['type' => $item['type'], 'id' => $item['id']], + ['type' => $this->type, 'id' => $item['id']], User::class, 'json', [AbstractNormalizer::GROUPS => ['read']], From 972657b38ecfdacaf3dcb8f6328fb63a7daca8fd Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 21 Jan 2022 15:53:52 +0100 Subject: [PATCH 2/4] different dynamic entity picker types created --- .../EntityToJsonTransformer.php | 6 +- .../Form/Type/PickUserDynamicType.php | 5 +- .../Resources/views/Form/fields.html.twig | 2 +- .../Form/Type/PickPersonDynamicType.php | 62 +++++++++++++++++++ .../Form/Type/PickThirdpartyDynamicType.php | 62 +++++++++++++++++++ 5 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php create mode 100644 src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php index 969247908..3b1909ba7 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php @@ -19,7 +19,7 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; use function array_key_exists; -class UserToJsonTransformer implements DataTransformerInterface +class EntityToJsonTransformer implements DataTransformerInterface { private DenormalizerInterface $denormalizer; @@ -75,8 +75,8 @@ class UserToJsonTransformer implements DataTransformerInterface return $this->denormalizer->denormalize( - ['type' => $this->type, 'id' => $item['id']], - User::class, + ['type' => $item['type'], 'id' => $item['id']], + $this->type, 'json', [AbstractNormalizer::GROUPS => ['read']], ); diff --git a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php index 52798608e..ec7590992 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Form\Type; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Form\Type\DataTransformer\EntityToJsonTransformer; use Chill\MainBundle\Form\Type\DataTransformer\UserToJsonTransformer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; @@ -38,7 +39,7 @@ class PickUserDynamicType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->addViewTransformer(new UserToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'])); + $builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'user')); } public function buildView(FormView $view, FormInterface $form, array $options) @@ -58,6 +59,6 @@ class PickUserDynamicType extends AbstractType public function getBlockPrefix() { - return 'pick_user_dynamic'; + return 'pick_entity_dynamic'; } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 25f1363c3..8bb09623f 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -216,7 +216,7 @@ {% endif %} {% endblock %} -{% block pick_user_dynamic_widget %} +{% block pick_entity_dynamic_widget %}
{% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php new file mode 100644 index 000000000..41c90406f --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php @@ -0,0 +1,62 @@ +denormalizer = $denormalizer; + $this->serializer = $serializer; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'person')); + } + + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars['multiple'] = $options['multiple']; + $view->vars['types'] = ['person']; + $view->vars['uniqid'] = uniqid('pick_user_dyn'); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefault('multiple', false) + ->setAllowedTypes('multiple', ['bool']) + ->setDefault('compound', false); + } + + public function getBlockPrefix() + { + return 'pick_entity_dynamic'; + } +} diff --git a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php new file mode 100644 index 000000000..7c2fbff4f --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php @@ -0,0 +1,62 @@ +denormalizer = $denormalizer; + $this->serializer = $serializer; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'thirdparty')); + } + + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars['multiple'] = $options['multiple']; + $view->vars['types'] = ['thirdparty']; + $view->vars['uniqid'] = uniqid('pick_user_dyn'); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefault('multiple', false) + ->setAllowedTypes('multiple', ['bool']) + ->setDefault('compound', false); + } + + public function getBlockPrefix() + { + return 'pick_entity_dynamic'; + } +} From 84993ca05b932cc91b7609e64ca91bb0fb18eae8 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 21 Jan 2022 15:55:22 +0100 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ad04a636..222de12ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to * [main] location form type: fix unmapped address field (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/246) * [activity] fix wrong import of js assets for adding and viewing documents in activity (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/83 & https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/176) * [person]: space added between deathdate and age in twig renderbox (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/380) +* [forms] dynamic picker types for user/person/thirdparty types created (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/386) ### test release 2022-01-17 From 92788ccdc0ae5ff7163f19f31ee84b14d8a697bd Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 21 Jan 2022 15:58:55 +0100 Subject: [PATCH 4/4] php cs-fixes --- .../Form/Type/DataTransformer/EntityToJsonTransformer.php | 4 ++-- .../ChillMainBundle/Form/Type/PickUserDynamicType.php | 1 - src/Bundle/ChillPersonBundle/Form/CreationPersonType.php | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php index 3b1909ba7..984560a12 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php @@ -25,10 +25,10 @@ class EntityToJsonTransformer implements DataTransformerInterface private bool $multiple; - private string $type; - private SerializerInterface $serializer; + private string $type; + public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, bool $multiple, string $type) { $this->denormalizer = $denormalizer; diff --git a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php index ec7590992..3bc4df436 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php @@ -13,7 +13,6 @@ namespace Chill\MainBundle\Form\Type; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Form\Type\DataTransformer\EntityToJsonTransformer; -use Chill\MainBundle\Form\Type\DataTransformer\UserToJsonTransformer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; diff --git a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php index 82437eb30..a33858c02 100644 --- a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php @@ -61,13 +61,13 @@ final class CreationPersonType extends AbstractType 'required' => false, ]) ->add('phonenumber', TelType::class, [ - 'required' => false + 'required' => false, ]) ->add('mobilenumber', TelType::class, [ - 'required' => false + 'required' => false, ]) ->add('email', EmailType::class, [ - 'required' => false + 'required' => false, ]); if ($this->askCenters) {