src/Form/PostType.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Post;
  4. use App\Entity\Grade;
  5. use App\Entity\Domaine;
  6. use App\Entity\Direction;
  7. use App\Entity\Configuration;
  8. use App\Repository\GradeRepository;
  9. use App\Repository\DomaineRepository;
  10. use App\Repository\DirectionRepository;
  11. use Symfony\Component\Form\AbstractType;
  12. use Symfony\UX\Dropzone\Form\DropzoneType;
  13. use App\Repository\ConfigurationRepository;
  14. use App\Validator\Constraints\IsEmailOrigin;
  15. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  16. use Symfony\Component\Form\FormBuilderInterface;
  17. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  18. use Symfony\Component\Validator\Constraints\File;
  19. use Symfony\Component\Validator\Constraints\Email;
  20. use Symfony\Component\Validator\Constraints\Length;
  21. use Symfony\Component\Validator\Constraints\NotBlank;
  22. use Symfony\Component\OptionsResolver\OptionsResolver;
  23. use Symfony\Component\Form\Extension\Core\Type\FileType;
  24. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  25. class PostType extends AbstractType
  26. {
  27.     private ConfigurationRepository $configurationRepository;
  28.     public function __construct(ConfigurationRepository $configurationRepository)
  29.     {
  30.         $this->configurationRepository $configurationRepository;
  31.     }
  32.     /**
  33.      * Récupère l'objet Configuration en bdd
  34.      *
  35.      * @return Configuration
  36.      */
  37.     public function getConfiguration(): Configuration
  38.     {
  39.         return $this->configurationRepository->findOneBy(['uuid' => Configuration::UNIQUE_UUID]);
  40.     }
  41.     
  42.     public function buildForm(FormBuilderInterface $builder, array $options): void
  43.     {
  44.         $builder
  45.             ->add('titre'null, [
  46.                 'label' => 'Titre<span class=\'text-danger\'>*</span>',
  47.                 'label_html'=> true,
  48.                 'required' => false,
  49.                 'constraints' => [
  50.                     new NotBlank([
  51.                         'message' => 'Veuillez entrer un titre',
  52.                     ]),
  53.                 ],
  54.                 'attr' => [
  55.                     'placeholder' => 'Saisir un titre'
  56.                 ]
  57.             ])
  58.             // ->add('description', CKEditorType::class, [
  59.             //     'config_name' => 'front_office',
  60.             //     'required' => false,
  61.             //     'label' => 'Contenu<span class=\'text-danger\'>*</span>',
  62.             //     'label_html'=> true,
  63.             //     'constraints' => [
  64.             //         new NotBlank([
  65.             //             'message' => 'Veuillez entrer un contenu',
  66.             //         ]),
  67.             //     ],
  68.                 
  69.             // ])
  70.             ->add('description'null , [
  71.                 'required' => false,
  72.                 'label' => 'Description<span class=\'text-danger\'>*</span>',
  73.                 'label_html'=> true,
  74.                 'attr' => [
  75.                     'rows' => 6
  76.                 ],
  77.                 'help' => 'Veuillez saisir une description en moins de ' $this->getConfiguration()->getSizePost() . ' caractères',
  78.                 'constraints' => [
  79.                     new NotBlank([
  80.                         'message' => 'Veuillez saisir une description',
  81.                     ]),
  82.                     new Length([
  83.                         'min' => 10,
  84.                         'minMessage' => 'Veuillez saisir plus de 10 caractères',
  85.                         'max' => $this->getConfiguration()->getSizePost(),
  86.                         'maxMessage' => 'Veuillez saisir moins de ' $this->getConfiguration()->getSizePost() . ' caractères',
  87.                     ])
  88.                 ],
  89.             ])
  90.             // ->add('fichier', DropzoneType::class, [
  91.             //     'attr' => [
  92.             //         'placeholder' => 'Drag and drop un fichier',
  93.             //     ],
  94.             //     'mapped' => false,
  95.             //     'required' => false,
  96.             // ])
  97.             // ->add('domaine', EntityType::class, [
  98.             //     'class' => Domaine::class,
  99.             //     'choice_label' => 'nom',
  100.             //     'label' => 'Domaine',
  101.             //     'placeholder' => 'Saisir un domaine',
  102.             //     'required' => false,
  103.             //     'query_builder' => function(DomaineRepository $er) {
  104.             //         return $er->createQueryBuilder('p')
  105.             //             ->orderBy('p.nom', 'ASC')
  106.             //             ->andWhere('p.statut = :val')
  107.             //             ->setParameter('val', 1)
  108.             //         ;
  109.             //     }
  110.             // ])
  111.             ->add('hashtag'null, [
  112.                 'label' => 'Hashtag',
  113.                 'attr' => [
  114.                     'placeholder' => 'Saisir votre hashtag',
  115.                 ],
  116.                 'required' => false,
  117.             ])
  118.             ->add('fichier'FileType::class, [
  119.                 'mapped' => false,
  120.                 'label' => false,
  121.                 'required' => false,
  122.                 'attr' => [
  123.                     'onchange' => 'loadFile(event)'
  124.                 ],
  125.                 'constraints' => [
  126.                     new File([
  127.                         // 'mimeTypes' => [
  128.                         //     'image/png',
  129.                         //     'image/jpg',
  130.                         //     'image/jpeg',
  131.                         //     'image/gif',
  132.                         // ],
  133.                         //'mimeTypesMessage' => 'Extensions Autorisées : PNG JPG JPEG GIF'
  134.                     ])
  135.                 ]
  136.             ])
  137.             
  138.         ;
  139.     }
  140.     public function configureOptions(OptionsResolver $resolver): void
  141.     {
  142.         $resolver->setDefaults([
  143.             'data_class' => Post::class,
  144.         ]);
  145.     }
  146. }