<?php
namespace App\Form;
use App\Entity\Category;
use App\Entity\Contact;
use App\Entity\PhaseEvolution;
use App\Entity\PostCategory;
use App\Entity\ProductAddon;
use App\Entity\SubCategory;
use App\Repository\CategoryRepository;
use App\Repository\PostCategoryRepository;
use App\Repository\SubCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Persistence\ManagerRegistry;
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\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
class PostsFilterType extends AbstractType
{
protected $em;
public function __construct(ManagerRegistry $em)
{
$this->em = $em;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add("offset", HiddenType::class)
->add("search", TextType::class, [
"required" => false,
"label" => false,
"attr" => ["placeholder" => "posts_type.search.placeholder"]
])
->add('postCategory', EntityType::class, array(
'class' => PostCategory::class,
'query_builder' => function (PostCategoryRepository $er) use ($options) {
return $er->createQueryBuilder('a');
},
'choice_label' => function ($postCategory) {
return $postCategory->getTitle();
},
"multiple" => false,
"required" => false,
"expanded" => false,
"placeholder" => "posts_type.postCategory.label",
"attr" => ["class" => "postCategory"]
//'by_reference' => false,
));
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => null,
]);
}
}