1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\AirBundle\Form
;
14 use Doctrine\ORM\EntityManagerInterface
;
16 use Symfony\Component\Form\AbstractType
;
17 use Symfony\Component\Form\Extension\Core\Type\ChoiceType
;
18 use Symfony\Component\Form\Extension\Core\Type\SubmitType
;
19 use Symfony\Component\Form\FormBuilderInterface
;
20 use Symfony\Component\OptionsResolver\OptionsResolver
;
21 use Symfony\Contracts\Translation\TranslatorInterface
;
23 use Rapsys\AirBundle\Transformer\DanceTransformer
;
28 class DanceType
extends AbstractType
{
32 * @param EntityManagerInterface $manager The entity manager
33 * @param ?TranslatorInterface $translator The translator instance
35 public function __construct(protected EntityManagerInterface
$manager, protected ?TranslatorInterface
$translator = null) {
41 public function buildForm(FormBuilderInterface
$builder, array $options): void {
44 ->create('dances', ChoiceType
::class, ['attr' => ['placeholder' => 'Your dance']/*, 'by_reference' => false*/, 'choice_attr' => ['class' => 'row'], 'choice_translation_domain' => false, 'choices' => $options['dance_choices'], 'multiple' => true, 'preferred_choices' => $options['dance_favorites'], 'required' => false])
45 ->addModelTransformer(new DanceTransformer($this->manager
))
49 $builder->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
55 public function configureOptions(OptionsResolver
$resolver): void {
57 $resolver->setDefaults(['error_bubbling' => true, 'dance_choices' => [], 'dance_default' => null, 'dance_favorites' => []]);
60 $resolver->setAllowedTypes('dance_choices', 'array');
63 $resolver->setAllowedTypes('dance_default', [Dance
::class, 'null']);
66 $resolver->setAllowedTypes('dance_favorites', 'array');
73 public function getName(): string {
74 return 'rapsysair_application';