issue641: create 2 new Select2 formType (for actions and issues)

This commit is contained in:
Mathieu Jaumotte 2022-10-10 17:39:13 +02:00
parent fd24ba618d
commit c3f9ce1ea6
6 changed files with 118 additions and 18 deletions

View File

@ -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
]);
}

View File

@ -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
]);
}

View File

@ -0,0 +1,51 @@
<?php
namespace Chill\PersonBundle\Form\Type;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class Select2SocialActionType extends AbstractType
{
private SocialActionRender $actionRender;
public function __construct(SocialActionRender $actionRender)
{
$this->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';
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace Chill\PersonBundle\Form\Type;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class Select2SocialIssueType extends AbstractType
{
private SocialIssueRender $issueRender;
public function __construct(SocialIssueRender $issueRender)
{
$this->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';
}
}

View File

@ -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

View File

@ -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