issue649: new formType to use select2 with LocationTypeFilter

This commit is contained in:
2022-10-10 15:59:16 +02:00
parent 087270829e
commit 7276cb971f
3 changed files with 55 additions and 8 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace Chill\MainBundle\Form\Type;
use Chill\MainBundle\Entity\LocationType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class Select2LocationTypeType extends AbstractType
{
private TranslatableStringHelper $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper)
{
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('locationtype', EntityType::class, [
'class' => LocationType::class,
'choice_label' => function (LocationType $type) {
return $this->translatableStringHelper->localize($type->getTitle());
},
'placeholder' => 'Pick a location type',
'required' => false,
'label' => $options['label'],
'label_attr' => $options['label_attr'],
'multiple' => $options['multiple'],
'attr' => ['class' => 'select2'],
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('label', 'Location type')
->setDefault('label_attr', [])
->setDefault('multiple', false)
->setAllowedTypes('multiple', ['bool'])
;
}
public function getBlockPrefix()
{
return 'select2_location_type_type';
}
}

View File

@@ -227,6 +227,7 @@ never: jamais
Create a new location: Créer une nouvelle localisation
Location list: Liste des localisations
Location type: Type de localisation
Pick a location type: Choisir un type de localisation
Phonenumber1: Numéro de téléphone
Phonenumber2: Autre numéro de téléphone
Location configuration: Configuration des localisations