issue649: adapt existing UserCurrentLocationType to use select2 with AdministrativeLocationFilter

This commit is contained in:
2022-10-10 15:25:07 +02:00
parent 01acfeb58f
commit 999d4e2038
2 changed files with 52 additions and 19 deletions

View File

@@ -17,6 +17,9 @@ 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\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UserCurrentLocationType extends AbstractType
{
@@ -32,6 +35,7 @@ class UserCurrentLocationType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
//dump($options);
$builder
->add('currentLocation', EntityType::class, [
'class' => Location::class,
@@ -43,7 +47,29 @@ class UserCurrentLocationType extends AbstractType
},
'placeholder' => 'Pick a location',
'required' => false,
'label' => $options['label'],
'label_attr' => $options['label_attr'],
'multiple' => $options['multiple'],
'attr' => ['class' => 'select2'],
]);
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('label', 'Current location')
->setDefault('label_attr', [])
->setDefault('multiple', false)
->setAllowedTypes('multiple', ['bool'])
;
}
public function getBlockPrefix()
{
return 'user_current_location_type';
}
}