<?php
namespace App\Form;
use App\Entity\Post;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title', TextType::class, [
'label' => 'Titre',
'attr' => [
'class' => 'form-control'
],
'label_attr' => [
'class' => 'mt-3'
],
])
->add('content', TextareaType::class, [
'label' => 'Description',
'attr' => [
'class' => 'form-control',
'rows' => 8
],
'label_attr' => [
'class' => 'mt-3'
],
])
->add('postImages', CollectionType::class, [
'label' => false,
'entry_type' => PostImageType::class,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Post::class,
]);
}
}