121 lines
3.2 KiB
PHP
121 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Form\Blog;
|
|
|
|
use App\Entity\Blog\Comment;
|
|
use Symfony\Component\Form\AbstractType;
|
|
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;
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
|
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(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$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,
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'captcha',
|
|
CaptchaType::class,
|
|
[
|
|
'invalid_message' => 'Code invalide',
|
|
'label' => 'Captcha',
|
|
'max_front_lines' => 1,
|
|
'width' => 140,
|
|
'height' => 50,
|
|
'length' => 3,
|
|
'reload' => true,
|
|
'as_url' => true,
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'parentCommentId',
|
|
HiddenType::class,
|
|
[
|
|
'mapped' => false,
|
|
]
|
|
);
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'data_class' => Comment::class,
|
|
]);
|
|
}
|
|
}
|