src/Form/PostType.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Post;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. class PostType extends AbstractType
  11. {
  12.     public function buildForm(FormBuilderInterface $builder, array $options): void
  13.     {
  14.         $builder
  15.             ->add('title'TextType::class, [
  16.                 'label' => 'Titre',
  17.                 'attr' => [
  18.                     'class' => 'form-control'
  19.                 ],
  20.                 'label_attr' => [
  21.                     'class' => 'mt-3'
  22.                 ],
  23.             ])
  24.             ->add('content'TextareaType::class, [
  25.                 'label' => 'Description',
  26.                 'attr' => [
  27.                     'class' => 'form-control',
  28.                     'rows' => 8
  29.                 ],
  30.                 'label_attr' => [
  31.                     'class' => 'mt-3'
  32.                 ],
  33.             ])
  34.             ->add('postImages'CollectionType::class, [
  35.                 'label' => false,
  36.                 'entry_type' => PostImageType::class,
  37.                 'allow_add' => true,
  38.                 'allow_delete' => true,
  39.                 'prototype' => true,
  40.                 'by_reference' => false
  41.             ])
  42.         ;
  43.     }
  44.     public function configureOptions(OptionsResolver $resolver): void
  45.     {
  46.         $resolver->setDefaults([
  47.             'data_class' => Post::class,
  48.         ]);
  49.     }
  50. }