src/Form/SuggestEventType.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\OptionsResolver\OptionsResolver;
  6. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  9. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  10. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  11. use Symfony\Component\Form\Extension\Core\Type\FileType;
  12. // use Symfony\Component\Form\Extension\Core\Type\NumberType;
  13. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. use Gregwar\CaptchaBundle\Type\CaptchaType;
  17. use Symfony\Component\Validator\Constraints\File;
  18. use App\Entity\Structure;
  19. class SuggestEventType extends AbstractType
  20. {
  21.     /**
  22.     * @var AuthorizationCheckerInterface
  23.     */
  24.     private $authorizationChecker=null;
  25.     public function __construct(AuthorizationCheckerInterface $authorizationChecker)
  26.     {
  27.           $this->authorizationChecker=$authorizationChecker;
  28.     }
  29.     public function buildForm(FormBuilderInterface $builder, array $options) {
  30.         $fileConstraints = [
  31.             new File([
  32.                 'maxSize' => '2048k',
  33.                 'mimeTypes' => [
  34.                     'application/pdf',
  35.                     'application/x-pdf',
  36.                     'image/gif',
  37.                     'image/jpeg',
  38.                     'image/png',
  39.                     'text/plain',
  40.                     'application/zip',
  41.                 ],
  42.                 'mimeTypesMessage' => 'Seuls les fichiers ayant l\'une de ces extensions sont acceptés : .pdf,.jpg,.jpeg,.png,.gif,.txt,.zip',
  43.                 'maxSizeMessage' => 'Chaque fichier doit avoir un poids inférieur à 2Mo (2048ko)',
  44.             ])
  45.         ];
  46.         $builder
  47.             ->add('email',  EmailType::class, [
  48.                 'label' => "Votre e-mail",
  49.                 'mapped' => false,
  50.                 'help' => 'Un message de confirmation sera envoyé à cette adresse'
  51.             ])
  52.             ->add('tel',   TextType::class, [
  53.                 'label' => "Votre numéro de téléphone",
  54.                 'required'   => false,
  55.                 'mapped' => false
  56.             ])
  57.             ->add('title'TextType::class, [
  58.                 'label' => "Titre de l'événement ",
  59.                 'required'   => true,
  60.             ])
  61.             ->add('content'TextareaType::class, [
  62.                 'label' => "Description de l'événement "
  63.             ])
  64.             ->add('eventStart'DateTimeType::class, [
  65.                 'label' => "Date et heure de début l'événement",
  66.                 'data' => new \DateTime('now'),
  67.                 'mapped' => false
  68.             ])
  69.             ->add('eventEnd'DateTimeType::class, [
  70.                 'label' => "Date et heure de fin l'événement",
  71.                 'data' => new \DateTime('+7 day'),
  72.                 'required'   => false,
  73.                 'mapped' => false
  74.             ])
  75.             ->add('allDay'CheckboxType::class, [
  76.                 'label' => "Événement sur la journée",
  77.                 'required'   => false,
  78.                 'mapped' => false
  79.             ])
  80.             ->add('lieu'TextType::class, [
  81.                 'label' => "Lieu de l'événement",
  82.                 'required'   => false,
  83.                 'mapped' => false
  84.             ])
  85.             ->add('adresse'TextAreaType::class, [
  86.                 'label' => "Adresse du lieu",
  87.                 'required' => false,
  88.                 'mapped' => false
  89.             ])
  90.             // ->add('eventHosters', EntityType::class, [
  91.             //     'class' => Structure::class,
  92.             //     'choice_label' => 'title',
  93.             //     'attr' => ['class' => 'tinymce'],
  94.             //     // 'multiple' => true,
  95.             //     // 'expanded' => true,
  96.             // ])
  97.             ->add('fichier1'FileType::class, [
  98.                 'label' => "Fichier 1 (pdf, image, txt, zip / max 2Mo)",
  99.                 'required' => false,
  100.                 'mapped' => false,
  101.                 'constraints' => $fileConstraints,
  102.             ])
  103.             ->add('fichier2'FileType::class, [
  104.                 'label' => "Fichier 2 (pdf, image, txt, zip / max 2Mo)",
  105.                 'required' => false,
  106.                 'mapped' => false,
  107.                 'constraints' => $fileConstraints,
  108.             ])
  109.             ->add('fichier3'FileType::class, [
  110.                 'label' => "Fichier 3 (pdf, image, txt, zip / max 2Mo)",
  111.                 'required' => false,
  112.                 'mapped' => false
  113.             ])
  114.         ;
  115.         if(!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
  116.             $builder->add('captcha'CaptchaType::class, [
  117.                 'label' => "Anti-robot. Saisissez le texte de l'image..."
  118.             ]);
  119.         }
  120.         $builder->add('suggest'SubmitType::class, [
  121.             'attr' => [
  122.                 'class' => 'btn-icig'
  123.             ],
  124.             'label' => "Proposer"
  125.         ]);
  126.     }
  127.     public function configureOptions(OptionsResolver $resolver)
  128.     {
  129.         $resolver->setDefaults([
  130.             // Configure your form options here
  131.             // 'data_class' => Product::class,
  132.         ]);
  133.     }
  134. }