259 lines
6.7 KiB
PHP
259 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Form\Blog;
|
|
|
|
use App\Entity\Blog\Category;
|
|
use App\Entity\Blog\Post;
|
|
use Doctrine\ORM\EntityRepository;
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
|
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
|
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
|
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\Image;
|
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
|
use Symfony\Component\Validator\Constraints\Range;
|
|
use Symfony\Component\Validator\Constraints\Url;
|
|
|
|
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(
|
|
'contentFormat',
|
|
ChoiceType::class,
|
|
[
|
|
'label' => 'Format',
|
|
'required' => true,
|
|
'choices' => [
|
|
'HTML' => 'html',
|
|
'Markdown' => 'markdown',
|
|
],
|
|
'constraints' => [
|
|
new NotBlank(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'content',
|
|
TextareaType::class,
|
|
[
|
|
'label' => 'Contenu',
|
|
'required' => false,
|
|
'attr' => [
|
|
'data-simplemde' => '',
|
|
'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' => Post::DRAFT,
|
|
'Publié' => Post::PUBLISHED,
|
|
],
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new NotBlank(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'publishedAt',
|
|
DateTimeType::class,
|
|
[
|
|
'label' => 'Date de publication',
|
|
'required' => false,
|
|
'html5' => false,
|
|
'widget' => 'single_text',
|
|
'format' => 'dd/MM/yyyy hh:mm',
|
|
'attr' => [
|
|
'data-datetime' => '',
|
|
],
|
|
'constraints' => [
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'image',
|
|
FileType::class,
|
|
[
|
|
'label' => 'Image',
|
|
'required' => false,
|
|
'data_class' => null,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new Image(),
|
|
],
|
|
]
|
|
);
|
|
|
|
// $builder->add(
|
|
// 'tags',
|
|
// 'text',
|
|
// [
|
|
// 'constraints' => [
|
|
// ],
|
|
// ]
|
|
// );
|
|
|
|
$builder->add(
|
|
'isQuick',
|
|
CheckboxType::class,
|
|
[
|
|
'label' => 'Quick',
|
|
'required' => false,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'quickUrl',
|
|
TextType::class,
|
|
[
|
|
'label' => 'Url',
|
|
'required' => false,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new Url(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'quickImage',
|
|
TextType::class,
|
|
[
|
|
'label' => 'Image',
|
|
'required' => false,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new Url(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'quickVideo',
|
|
TextType::class,
|
|
[
|
|
'label' => 'Vidéo',
|
|
'required' => false,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new Url(),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'quickVideoWidth',
|
|
NumberType::class,
|
|
[
|
|
'label' => 'Vidéo (largeur)',
|
|
'required' => false,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new Range(['min' => 0]),
|
|
],
|
|
]
|
|
);
|
|
|
|
$builder->add(
|
|
'quickVideoHeight',
|
|
NumberType::class,
|
|
[
|
|
'label' => 'Vidéo (hauteur)',
|
|
'required' => false,
|
|
'attr' => [
|
|
],
|
|
'constraints' => [
|
|
new Range(['min' => 0]),
|
|
],
|
|
]
|
|
);
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'data_class' => Post::class,
|
|
]);
|
|
}
|
|
}
|