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

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

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';
}
}