deblan.io-murph/src/Form/Blog/Filter/PostFilterType.php

112 lines
2.9 KiB
PHP

<?php
namespace App\Form\Blog\Filter;
use App\Entity\Blog\Category;
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\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\ChoiceList\ChoiceList;
class PostFilterType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'title',
TextType::class,
[
'label' => 'Titre',
'required' => false,
'attr' => [
],
'constraints' => [
],
]
);
$builder->add(
'contentFormat',
ChoiceType::class,
[
'label' => 'Format',
'required' => false,
'choices' => [
'HTML' => 'html',
'Markdown' => 'markdown',
],
'constraints' => [
],
]
);
$builder->add(
'category',
EntityType::class,
[
'label' => 'Catégories',
'class' => Category::class,
'choice_label' => 'title',
'choice_value' => 'id',
'required' => false,
'attr' => [
],
'query_builder' => function (EntityRepository $repo) {
return $repo->createQueryBuilder('a')
->orderBy('a.title', 'ASC')
;
},
'constraints' => [
],
]
);
$builder->add(
'status',
ChoiceType::class,
[
'label' => 'Statut',
'required' => false,
'choices' => [
'Brouillon' => 0,
'Publié' => 1,
],
'attr' => [
],
'constraints' => [
],
]
);
$builder->add(
'isQuick',
ChoiceType::class,
[
'label' => 'Quick',
'required' => false,
'choices' => [
'Anyway' => null,
'Yes' => true,
'No' => false,
],
'attr' => [
],
'constraints' => [
],
]
);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => null,
'csrf_protection' => false,
]);
}
}