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 Symfony\Component\Form\AbstractType
;
15 use Symfony\Component\Form\FormBuilderInterface
;
16 use Symfony\Component\OptionsResolver\OptionsResolver
;
17 use Symfony\Bridge\Doctrine\Form\Type\EntityType
;
18 use Symfony\Component\Form\Extension\Core\Type\ChoiceType
;
19 use Symfony\Component\Form\Extension\Core\Type\DateType
;
20 use Symfony\Component\Form\Extension\Core\Type\SubmitType
;
21 use Symfony\Component\Validator\Constraints\Type
;
22 use Symfony\Component\Validator\Constraints\NotBlank
;
24 use Rapsys\AirBundle\Entity\Dance
;
25 use Rapsys\AirBundle\Entity\Location
;
26 use Rapsys\AirBundle\Entity\Slot
;
31 class ApplicationType
extends AbstractType
{
35 public function buildForm(FormBuilderInterface
$builder, array $options): void {
37 $builder->add('dance', EntityType
::class, ['class' => 'Rapsys\AirBundle\Entity\Dance', 'choices' => $options['dance_choices'], 'preferred_choices' => $options['dance_favorites'], 'attr' => ['placeholder' => 'Your dance'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your dance'])], 'data' => $options['dance_default']]);
40 $builder->add('date', DateType
::class, ['attr' => ['placeholder' => 'Your date', 'class' => 'date'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'data' => new \
DateTime('+7 day'), 'constraints' => [new NotBlank(['message' => 'Please provide your date']), new Type(['type' => \DateTime
::class, 'message' => 'Your date doesn\'t seems to be valid'])]]);
43 $builder->add('location', EntityType
::class, ['class' => 'Rapsys\AirBundle\Entity\Location', 'choices' => $options['location_choices'], 'preferred_choices' => $options['location_favorites'], 'attr' => ['placeholder' => 'Your location'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'data' => $options['location_default']]);
46 $builder->add('slot', EntityType
::class, ['class' => 'Rapsys\AirBundle\Entity\Slot', 'attr' => ['placeholder' => 'Your slot'], 'constraints' => [new NotBlank(['message' => 'Please provide your slot'])], 'choice_translation_domain' => true, 'data' => $options['slot_default']]);
48 //Add extra user field
49 if (!empty($options['user'])) {
50 //XXX: choicetype used here to use our own custom translated string
51 $builder->add('user', ChoiceType
::class, ['attr' => ['placeholder' => 'Your user'], 'choice_translation_domain' => false, 'constraints' => [new NotBlank(['message' => 'Please provide your user'])], 'choices' => $options['user_choices'], 'data' => $options['user_default']]);
55 $builder->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
61 public function configureOptions(OptionsResolver
$resolver): void {
63 $resolver->setDefaults(['error_bubbling' => true, 'dance_choices' => [], 'dance_default' => null, 'dance_favorites' => [], 'location_choices' => [], 'location_default' => null, 'location_favorites' => [], 'slot_default' => null, 'user' => true, 'user_choices' => [], 'user_default' => 1]);
66 $resolver->setAllowedTypes('dance_choices', 'array');
69 $resolver->setAllowedTypes('dance_default', [Dance
::class, 'null']);
72 $resolver->setAllowedTypes('dance_favorites', 'array');
74 //Add location choices
75 $resolver->setAllowedTypes('location_choices', 'array');
77 //Add location default
78 $resolver->setAllowedTypes('location_default', [Location
::class, 'null']);
80 //Add location favorites
81 $resolver->setAllowedTypes('location_favorites', 'array');
84 $resolver->setAllowedTypes('slot_default', [Slot
::class, 'null']);
87 $resolver->setAllowedTypes('user', 'boolean');
90 $resolver->setAllowedTypes('user_choices', 'array');
93 $resolver->setAllowedTypes('user_default', 'integer');
99 public function getName(): string {
100 return 'rapsysair_application';