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) { 
  40                 $form->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']]); 
  43                 $form->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'])]]); 
  46                 $form->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']]); 
  49                 $form->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']]); 
  51                 //Add extra user field 
  52                 if (!empty($options['user'])) { 
  53                         //XXX: choicetype used here to use our own custom translated string 
  54                         $form->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']]); 
  58                 $form->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]); 
  67         public function configureOptions(OptionsResolver 
$resolver) { 
  69                 $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]); 
  72                 $resolver->setAllowedTypes('dance_choices', 'array'); 
  75                 $resolver->setAllowedTypes('dance_default', [Dance
::class, 'null']); 
  78                 $resolver->setAllowedTypes('dance_favorites', 'array'); 
  80                 //Add location choices 
  81                 $resolver->setAllowedTypes('location_choices', 'array'); 
  83                 //Add location default 
  84                 $resolver->setAllowedTypes('location_default', [Location
::class, 'null']); 
  86                 //Add location favorites 
  87                 $resolver->setAllowedTypes('location_favorites', 'array'); 
  90                 $resolver->setAllowedTypes('slot_default', [Slot
::class, 'null']); 
  93                 $resolver->setAllowedTypes('user', 'boolean'); 
  96                 $resolver->setAllowedTypes('user_choices', 'array'); 
  99                 $resolver->setAllowedTypes('user_default', 'integer'); 
 105         public function getName() { 
 106                 return 'rapsys_air_application';