<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
// use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Gregwar\CaptchaBundle\Type\CaptchaType;
use Symfony\Component\Validator\Constraints\File;
use App\Entity\Structure;
class SuggestEventType extends AbstractType
{
/**
* @var AuthorizationCheckerInterface
*/
private $authorizationChecker=null;
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker=$authorizationChecker;
}
public function buildForm(FormBuilderInterface $builder, array $options) {
$fileConstraints = [
new File([
'maxSize' => '2048k',
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
'image/gif',
'image/jpeg',
'image/png',
'text/plain',
'application/zip',
],
'mimeTypesMessage' => 'Seuls les fichiers ayant l\'une de ces extensions sont acceptés : .pdf,.jpg,.jpeg,.png,.gif,.txt,.zip',
'maxSizeMessage' => 'Chaque fichier doit avoir un poids inférieur à 2Mo (2048ko)',
])
];
$builder
->add('email', EmailType::class, [
'label' => "Votre e-mail",
'mapped' => false,
'help' => 'Un message de confirmation sera envoyé à cette adresse'
])
->add('tel', TextType::class, [
'label' => "Votre numéro de téléphone",
'required' => false,
'mapped' => false
])
->add('title', TextType::class, [
'label' => "Titre de l'événement ",
'required' => true,
])
->add('content', TextareaType::class, [
'label' => "Description de l'événement "
])
->add('eventStart', DateTimeType::class, [
'label' => "Date et heure de début l'événement",
'data' => new \DateTime('now'),
'mapped' => false
])
->add('eventEnd', DateTimeType::class, [
'label' => "Date et heure de fin l'événement",
'data' => new \DateTime('+7 day'),
'required' => false,
'mapped' => false
])
->add('allDay', CheckboxType::class, [
'label' => "Événement sur la journée",
'required' => false,
'mapped' => false
])
->add('lieu', TextType::class, [
'label' => "Lieu de l'événement",
'required' => false,
'mapped' => false
])
->add('adresse', TextAreaType::class, [
'label' => "Adresse du lieu",
'required' => false,
'mapped' => false
])
// ->add('eventHosters', EntityType::class, [
// 'class' => Structure::class,
// 'choice_label' => 'title',
// 'attr' => ['class' => 'tinymce'],
// // 'multiple' => true,
// // 'expanded' => true,
// ])
->add('fichier1', FileType::class, [
'label' => "Fichier 1 (pdf, image, txt, zip / max 2Mo)",
'required' => false,
'mapped' => false,
'constraints' => $fileConstraints,
])
->add('fichier2', FileType::class, [
'label' => "Fichier 2 (pdf, image, txt, zip / max 2Mo)",
'required' => false,
'mapped' => false,
'constraints' => $fileConstraints,
])
->add('fichier3', FileType::class, [
'label' => "Fichier 3 (pdf, image, txt, zip / max 2Mo)",
'required' => false,
'mapped' => false
])
;
if(!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
$builder->add('captcha', CaptchaType::class, [
'label' => "Anti-robot. Saisissez le texte de l'image..."
]);
}
$builder->add('suggest', SubmitType::class, [
'attr' => [
'class' => 'btn-icig'
],
'label' => "Proposer"
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// Configure your form options here
// 'data_class' => Product::class,
]);
}
}