2021-03-29 13:58:05 +02:00
|
|
|
<?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;
|
2021-03-30 13:40:46 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
2021-03-29 13:58:05 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
2021-03-30 21:17:05 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
2021-03-30 13:40:46 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
2021-03-29 13:58:05 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
2021-03-30 13:40:46 +02:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
2021-03-29 13:58:05 +02:00
|
|
|
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;
|
2022-03-25 11:54:56 +01:00
|
|
|
use App\Form\Type\SimpleMdTextareaType;
|
2022-03-26 14:31:37 +01:00
|
|
|
use App\Core\Form\Type\EditorJsTextareaType;
|
2023-01-06 13:14:42 +01:00
|
|
|
use App\Core\Form\FileManager\FilePickerType;
|
2023-05-12 20:56:54 +02:00
|
|
|
use App\Core\Form\Type\CollectionType as MurphCollectionType;
|
2021-03-29 13:58:05 +02:00
|
|
|
|
|
|
|
class PostType extends AbstractType
|
|
|
|
{
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
|
|
{
|
|
|
|
$builder->add(
|
|
|
|
'title',
|
|
|
|
TextType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Titre',
|
2021-04-01 12:17:14 +02:00
|
|
|
'required' => false,
|
2021-03-29 13:58:05 +02:00
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'contentFormat',
|
|
|
|
ChoiceType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Format',
|
|
|
|
'required' => true,
|
|
|
|
'choices' => [
|
|
|
|
'Markdown' => 'markdown',
|
2021-03-30 22:42:31 +02:00
|
|
|
'HTML' => 'html',
|
2022-03-26 14:31:37 +01:00
|
|
|
'Editor JS' => 'editorjs',
|
2021-03-29 13:58:05 +02:00
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
new NotBlank(),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2022-03-26 14:31:37 +01:00
|
|
|
$types = [
|
|
|
|
'markdown' => SimpleMdTextareaType::class,
|
|
|
|
'html' => SimpleMdTextareaType::class,
|
|
|
|
'editorjs' => EditorJsTextareaType::class,
|
|
|
|
];
|
|
|
|
|
2021-03-29 13:58:05 +02:00
|
|
|
$builder->add(
|
|
|
|
'content',
|
2022-03-26 14:31:37 +01:00
|
|
|
$types[$builder->getData()->getContentFormat() ?? 'markdown'],
|
2021-03-29 13:58:05 +02:00
|
|
|
[
|
|
|
|
'label' => 'Contenu',
|
|
|
|
'required' => false,
|
|
|
|
'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',
|
2021-03-29 22:43:44 +02:00
|
|
|
DateTimeType::class,
|
2021-03-29 13:58:05 +02:00
|
|
|
[
|
|
|
|
'label' => 'Date de publication',
|
|
|
|
'required' => false,
|
2021-11-06 14:51:52 +01:00
|
|
|
'html5' => true,
|
2021-03-29 13:58:05 +02:00
|
|
|
'widget' => 'single_text',
|
|
|
|
'attr' => [
|
2021-03-29 22:43:44 +02:00
|
|
|
'data-datetime' => '',
|
2021-03-29 13:58:05 +02:00
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'image',
|
|
|
|
FileType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Image',
|
|
|
|
'required' => false,
|
|
|
|
'data_class' => null,
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
new Image(),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2023-01-06 13:14:42 +01:00
|
|
|
$builder->add(
|
|
|
|
'image2',
|
|
|
|
FilePickerType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Image (carte)',
|
|
|
|
'required' => false,
|
|
|
|
'data_class' => null,
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-03-30 21:16:52 +02:00
|
|
|
$builder->add(
|
|
|
|
'tags',
|
|
|
|
CollectionType::class,
|
|
|
|
[
|
2021-05-12 16:00:15 +02:00
|
|
|
'label' => false,
|
2021-03-30 21:16:52 +02:00
|
|
|
'entry_type' => PostTagType::class,
|
|
|
|
'by_reference' => false,
|
|
|
|
'allow_add' => true,
|
|
|
|
'allow_delete' => true,
|
|
|
|
'prototype' => true,
|
|
|
|
]
|
|
|
|
);
|
2021-03-29 13:58:05 +02:00
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'isQuick',
|
|
|
|
CheckboxType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Quick',
|
|
|
|
'required' => false,
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
2021-03-30 13:40:46 +02:00
|
|
|
],
|
2021-03-29 13:58:05 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$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(),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2022-02-22 11:06:02 +01:00
|
|
|
$builder->add(
|
|
|
|
'quickShowVideo',
|
|
|
|
CheckboxType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Afficher la vidéo',
|
|
|
|
'required' => false,
|
|
|
|
'attr' => [
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2021-03-29 13:58:05 +02:00
|
|
|
$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]),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
2021-04-09 08:50:33 +02:00
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'notebook',
|
|
|
|
TextareaType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Carnet de notes',
|
|
|
|
'required' => false,
|
|
|
|
'attr' => [
|
|
|
|
'data-simplemde' => '',
|
|
|
|
'rows' => 20,
|
|
|
|
],
|
|
|
|
'constraints' => [
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
2023-05-12 20:56:54 +02:00
|
|
|
|
|
|
|
$builder->add(
|
|
|
|
'parameters',
|
|
|
|
MurphCollectionType::class,
|
|
|
|
[
|
|
|
|
'label' => 'Paramètres',
|
|
|
|
'entry_type' => PostParameterType::class,
|
|
|
|
'by_reference' => false,
|
|
|
|
'allow_add' => true,
|
|
|
|
'allow_delete' => true,
|
|
|
|
'prototype' => true,
|
|
|
|
'row_attr' => ['class' => 'mb-3'],
|
|
|
|
]
|
|
|
|
);
|
2021-03-29 13:58:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
|
|
{
|
|
|
|
$resolver->setDefaults([
|
|
|
|
'data_class' => Post::class,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|