From c3f9ce1ea6212c8e6e99fe632f9868cb53f40566 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 10 Oct 2022 17:39:13 +0200 Subject: [PATCH] issue641: create 2 new Select2 formType (for actions and issues) --- .../ACPFilters/BySocialActionFilter.php | 12 ++--- .../Filter/ACPFilters/BySocialIssueFilter.php | 12 ++--- .../Form/Type/Select2SocialActionType.php | 51 +++++++++++++++++++ .../Form/Type/Select2SocialIssueType.php | 51 +++++++++++++++++++ .../config/services/form.yaml | 8 +++ .../translations/messages.fr.yml | 2 + 6 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Form/Type/Select2SocialActionType.php create mode 100644 src/Bundle/ChillPersonBundle/Form/Type/Select2SocialIssueType.php diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php index e3ce8b287..4502450cb 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php @@ -13,11 +13,10 @@ namespace Chill\ActivityBundle\Export\Filter\ACPFilters; use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\PersonBundle\Entity\SocialWork\SocialAction; +use Chill\PersonBundle\Form\Type\Select2SocialActionType; use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; use function in_array; @@ -62,13 +61,8 @@ class BySocialActionFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_socialactions', EntityType::class, [ - 'class' => SocialAction::class, - 'choice_label' => function (SocialAction $sa) { - return $this->actionRender->renderString($sa, []); - }, - 'multiple' => true, - 'expanded' => true, + $builder->add('accepted_socialactions', Select2SocialActionType::class, [ + 'multiple' => true ]); } diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php index f5d552011..59d79d21d 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php @@ -13,11 +13,10 @@ namespace Chill\ActivityBundle\Export\Filter\ACPFilters; use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\PersonBundle\Entity\SocialWork\SocialIssue; +use Chill\PersonBundle\Form\Type\Select2SocialIssueType; use Chill\PersonBundle\Templating\Entity\SocialIssueRender; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; use function in_array; @@ -62,13 +61,8 @@ class BySocialIssueFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_socialissues', EntityType::class, [ - 'class' => SocialIssue::class, - 'choice_label' => function (SocialIssue $si) { - return $this->issueRender->renderString($si, []); - }, - 'multiple' => true, - 'expanded' => true, + $builder->add('accepted_socialissues', Select2SocialIssueType::class, [ + 'multiple' => true ]); } diff --git a/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialActionType.php b/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialActionType.php new file mode 100644 index 000000000..f1e8cd913 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialActionType.php @@ -0,0 +1,51 @@ +actionRender = $actionRender; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add('social_actions', EntityType::class, [ + 'class' => SocialAction::class, + 'choice_label' => function (SocialAction $sa) { + return $this->actionRender->renderString($sa, []); + }, + 'placeholder' => 'Pick a social action', + 'required' => false, + 'label' => $options['label'], + 'label_attr' => $options['label_attr'], + 'multiple' => $options['multiple'], + 'attr' => ['class' => 'select2'], + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefault('label', 'Social actions') + ->setDefault('label_attr', []) + ->setDefault('multiple', false) + ->setAllowedTypes('multiple', ['bool']) + ; + } + + public function getBlockPrefix(): string + { + return 'select2_social_action_type'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialIssueType.php b/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialIssueType.php new file mode 100644 index 000000000..49ee6d574 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialIssueType.php @@ -0,0 +1,51 @@ +issueRender = $issueRender; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add('social_issues', EntityType::class, [ + 'class' => SocialIssue::class, + 'choice_label' => function (SocialIssue $si) { + return $this->issueRender->renderString($si, []); + }, + 'placeholder' => 'Pick a social issue', + 'required' => false, + 'label' => $options['label'], + 'label_attr' => $options['label_attr'], + 'multiple' => $options['multiple'], + 'attr' => ['class' => 'select2'], + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefault('label', 'Social issues') + ->setDefault('label_attr', []) + ->setDefault('multiple', false) + ->setAllowedTypes('multiple', ['bool']) + ; + } + + public function getBlockPrefix(): string + { + return 'select2_social_issue_type'; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/form.yaml b/src/Bundle/ChillPersonBundle/config/services/form.yaml index 52bf1f494..85b97c86b 100644 --- a/src/Bundle/ChillPersonBundle/config/services/form.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/form.yaml @@ -27,3 +27,11 @@ services: $config: "%chill_person.accompanying_period_fields%" tags: - { name: form.type } + + Chill\PersonBundle\Form\Type\Select2SocialActionType: + autowire: true + autoconfigure: true + + Chill\PersonBundle\Form\Type\Select2SocialIssueType: + autowire: true + autoconfigure: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index a5040e6df..a755ce0f0 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -205,9 +205,11 @@ Resources: Interlocuteurs privilégiés Any requestor to this accompanying course: Aucun demandeur pour ce parcours Social action: Action d'accompagnement Social actions: Actions d'accompagnement +Pick a social action: Choisir une action d'accompagnement Last social actions: Les dernières actions d'accompagnement Social issue: Problématique sociale Social issues: Problématiques sociales +Pick a social issue: Choisir une problématique sociale Last events on accompanying course: Dernières actions de suivi Edit & activate accompanying course: Modifier et valider See accompanying periods: Voir toutes les périodes d'accompagnement