209 lines
5.5 KiB
PHP
209 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Form\Blog;
|
|
|
|
use App\Entity\Blog\Category;
|
|
use App\Entity\Blog\Post;
|
|
use App\Entity\User;
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
|
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
|
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;
|
|
use Symfony\Component\Validator\Constraints\Date;
|
|
use Symfony\Component\Validator\Constraints\Image;
|
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
|
|
|
class PostType extends AbstractType
|
|
{
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
$builder->add(
|
|
'title',
|
|
TextType::class,
|
|
[
|
|
'label' => 'Titre',
|
|
'required' => true,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new NotBlank(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'subTitle',
|
|
TextareaType::class,
|
|
[
|
|
'label' => 'Sous-titre',
|
|
'required' => false,
|
|
'attr' => [
|
|
'rows' => 5,
|
|
],
|
|
'constraints' => [
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'metaDescription',
|
|
TextType::class,
|
|
[
|
|
'label' => 'Meta description',
|
|
'required' => false,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'content',
|
|
TextareaType::class,
|
|
[
|
|
'label' => 'Contenu',
|
|
'required' => false,
|
|
'attr' => [
|
|
'data-tinymce' => '',
|
|
'rows' => 20,
|
|
],
|
|
'constraints' => [
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'slug',
|
|
TextType::class,
|
|
[
|
|
'label' => 'Slug',
|
|
'required' => false,
|
|
'help' => 'Laisser vide pour une génération automatique',
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'categories',
|
|
EntityType::class,
|
|
[
|
|
'label' => 'Catégories',
|
|
'class' => Category::class,
|
|
'choice_label' => 'title',
|
|
'required' => false,
|
|
'multiple' => true,
|
|
'attr' => [
|
|
'data-jschoice' => '',
|
|
],
|
|
'query_builder' => function (EntityRepository $repo) {
|
|
return $repo->createQueryBuilder('a')
|
|
->orderBy('a.title', 'ASC')
|
|
;
|
|
},
|
|
'constraints' => [
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'status',
|
|
ChoiceType::class,
|
|
[
|
|
'label' => 'Statut',
|
|
'required' => true,
|
|
'choices' => [
|
|
'Brouillon' => 0,
|
|
'Publié' => 1,
|
|
],
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new NotBlank(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'imageCaption',
|
|
TextType::class,
|
|
[
|
|
'label' => 'Titre de l\'image',
|
|
'required' => false,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'publishedAt',
|
|
DateType::class,
|
|
[
|
|
'label' => 'Date de publication',
|
|
'required' => false,
|
|
'html5' => true,
|
|
'widget' => 'single_text',
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new Date(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'author',
|
|
EntityType::class,
|
|
[
|
|
'label' => 'Auteur',
|
|
'class' => User::class,
|
|
'choice_label' => 'displayName',
|
|
'required' => true,
|
|
'attr' => [
|
|
],
|
|
'query_builder' => function (EntityRepository $repo) {
|
|
return $repo->createQueryBuilder('u')
|
|
->orderBy('u.displayName', 'ASC')
|
|
;
|
|
},
|
|
'constraints' => [
|
|
new NotBlank(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'image',
|
|
FileType::class,
|
|
[
|
|
'label' => 'Image',
|
|
'required' => false,
|
|
'data_class' => null,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new Image(),
|
|
],
|
|
]
|
|
);
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'data_class' => Post::class,
|
|
]);
|
|
}
|
|
}
|