mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
issue649: new formType to use select2 with LocationTypeFilter
This commit is contained in:
parent
087270829e
commit
7276cb971f
@ -12,12 +12,11 @@ declare(strict_types=1);
|
|||||||
namespace Chill\ActivityBundle\Export\Filter\ACPFilters;
|
namespace Chill\ActivityBundle\Export\Filter\ACPFilters;
|
||||||
|
|
||||||
use Chill\ActivityBundle\Export\Declarations;
|
use Chill\ActivityBundle\Export\Declarations;
|
||||||
use Chill\MainBundle\Entity\LocationType;
|
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
use Chill\MainBundle\Form\Type\Select2LocationTypeType;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Doctrine\ORM\Query\Expr\Andx;
|
use Doctrine\ORM\Query\Expr\Andx;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
|
|
||||||
@ -61,13 +60,9 @@ class LocationTypeFilter implements FilterInterface
|
|||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
$builder->add('accepted_locationtype', EntityType::class, [
|
$builder->add('accepted_locationtype', Select2LocationTypeType::class, [
|
||||||
'class' => LocationType::class,
|
|
||||||
'choice_label' => function (LocationType $type) {
|
|
||||||
return $this->translatableStringHelper->localize($type->getTitle());
|
|
||||||
},
|
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
//'label' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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';
|
||||||
|
}
|
||||||
|
}
|
@ -227,6 +227,7 @@ never: jamais
|
|||||||
Create a new location: Créer une nouvelle localisation
|
Create a new location: Créer une nouvelle localisation
|
||||||
Location list: Liste des localisations
|
Location list: Liste des localisations
|
||||||
Location type: Type de localisation
|
Location type: Type de localisation
|
||||||
|
Pick a location type: Choisir un type de localisation
|
||||||
Phonenumber1: Numéro de téléphone
|
Phonenumber1: Numéro de téléphone
|
||||||
Phonenumber2: Autre numéro de téléphone
|
Phonenumber2: Autre numéro de téléphone
|
||||||
Location configuration: Configuration des localisations
|
Location configuration: Configuration des localisations
|
||||||
|
Loading…
x
Reference in New Issue
Block a user