deblan.io-murph/src/Form/Blog/UserCommentType.php

121 lines
3.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Form\Blog;
use App\Entity\Blog\Comment;
use Symfony\Component\Form\AbstractType;
2021-03-30 20:40:36 +02:00
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
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;
2022-02-06 19:36:10 +01:00
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
2022-05-29 21:04:28 +02:00
use Gregwar\CaptchaBundle\Type\CaptchaType;
class UserCommentType 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' => [
],
'constraints' => [
new NotBlank(),
],
]
);
2022-02-06 19:36:10 +01:00
$builder->add(
'follow',
CheckboxType::class,
[
'label' => 'Recevoir une notification par e-mail si un commentaire est déposé sur cet article',
'mapped' => false,
'required' => false,
]
);
2022-05-29 21:04:28 +02:00
$builder->add(
'captcha',
CaptchaType::class,
[
'invalid_message' => 'Code invalide',
'label' => 'Captcha',
'max_front_lines' => 1,
'width' => 140,
'height' => 50,
'length' => 3,
2022-05-29 21:14:55 +02:00
'reload' => true,
'as_url' => true,
2022-05-29 21:04:28 +02:00
]
);
$builder->add(
'parentCommentId',
HiddenType::class,
[
'mapped' => false,
]
);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Comment::class,
]);
}
}