2021-03-30 19:35:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Blog;
|
|
|
|
|
|
|
|
use App\Entity\Blog\Comment;
|
2021-03-30 20:40:36 +02:00
|
|
|
use App\Entity\Blog\Post;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
2021-03-30 19:35:49 +02:00
|
|
|
use Symfony\Component\Form\AbstractType;
|
2021-03-30 20:40:36 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
2021-03-30 19:35:49 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
|
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
|
|
use Symfony\Component\Validator\Constraints\Email;
|
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
|
|
|
use Symfony\Component\Validator\Constraints\Url;
|
|
|
|
|
|
|
|
class CommentType extends AbstractType
|
|
|
|
{
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
|
|
{
|
|
|
|
$builder->add(
|
|
|
|
'author',
|
|
|
|
TextType::class,
|
|
|
|
[
|
|
|
|
'required' => true,
|
|
|
|
'label' => 'Auteur',
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
new NotBlank(),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'website',
|
|
|
|
UrlType::class,
|
|
|
|
[
|
|
|
|
'required' => false,
|
|
|
|
'label' => 'Site web',
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
new Url(),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'email',
|
|
|
|
EmailType::class,
|
|
|
|
[
|
|
|
|
'label' => 'E-mail (non publié)',
|
|
|
|
'required' => false,
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
new Email(),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'content',
|
|
|
|
TextareaType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Commentaire',
|
|
|
|
'required' => true,
|
|
|
|
'attr' => [
|
2021-04-09 08:50:33 +02:00
|
|
|
'rows' => 20,
|
2021-03-30 19:35:49 +02:00
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
new NotBlank(),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'post',
|
|
|
|
EntityType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Article',
|
|
|
|
'class' => Post::class,
|
|
|
|
'choice_label' => 'title',
|
|
|
|
'required' => true,
|
|
|
|
'multiple' => false,
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'query_builder' => function (EntityRepository $repo) {
|
|
|
|
return $repo->createQueryBuilder('p')
|
|
|
|
->orderBy('p.id', 'DESC')
|
|
|
|
;
|
|
|
|
},
|
|
|
|
'constraints' => [
|
|
|
|
new NotBlank(),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'parentComment',
|
|
|
|
EntityType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Réponse à',
|
|
|
|
'class' => Comment::class,
|
|
|
|
'required' => false,
|
|
|
|
'multiple' => false,
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'query_builder' => function (EntityRepository $repo) {
|
|
|
|
return $repo->createQueryBuilder('c')
|
|
|
|
->orderBy('c.id', 'DESC')
|
|
|
|
;
|
|
|
|
},
|
|
|
|
'constraints' => [
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'isActive',
|
|
|
|
CheckboxType::class,
|
|
|
|
[
|
|
|
|
'label' => 'En ligne',
|
|
|
|
'required' => false,
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
|
|
{
|
|
|
|
$resolver->setDefaults([
|
|
|
|
'data_class' => Comment::class,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|