src/Form/PostsFilterType.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Category;
  4. use App\Entity\Contact;
  5. use App\Entity\PhaseEvolution;
  6. use App\Entity\PostCategory;
  7. use App\Entity\ProductAddon;
  8. use App\Entity\SubCategory;
  9. use App\Repository\CategoryRepository;
  10. use App\Repository\PostCategoryRepository;
  11. use App\Repository\SubCategoryRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Persistence\ManagerRegistry;
  14. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  15. use Symfony\Component\Form\AbstractType;
  16. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  17. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  18. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  19. use Symfony\Component\Form\Extension\Core\Type\TextType;
  20. use Symfony\Component\Form\FormBuilderInterface;
  21. use Symfony\Component\Form\FormEvent;
  22. use Symfony\Component\Form\FormEvents;
  23. use Symfony\Component\Form\FormInterface;
  24. use Symfony\Component\OptionsResolver\OptionsResolver;
  25. use Symfony\Component\Validator\Constraints\NotBlank;
  26. class PostsFilterType extends AbstractType
  27. {
  28.     protected $em;
  29.     public function __construct(ManagerRegistry $em)
  30.     {
  31.         $this->em $em;
  32.     }
  33.     public function buildForm(FormBuilderInterface $builder, array $options): void
  34.     {
  35.         $builder
  36.             ->add("offset"HiddenType::class)
  37.             ->add("search"TextType::class, [
  38.                 "required" => false,
  39.                 "label" => false,
  40.                 "attr" => ["placeholder" => "posts_type.search.placeholder"]
  41.             ])
  42.             ->add('postCategory'EntityType::class, array(
  43.                 'class' => PostCategory::class,
  44.                 'query_builder' => function (PostCategoryRepository $er) use ($options) {
  45.                     return $er->createQueryBuilder('a');
  46.                 },
  47.                 'choice_label' => function ($postCategory) {
  48.                     return $postCategory->getTitle();
  49.                 },
  50.                 "multiple" => false,
  51.                 "required" => false,
  52.                 "expanded" => false,
  53.                 "placeholder" => "posts_type.postCategory.label",
  54.                 "attr" => ["class" => "postCategory"]
  55.                 //'by_reference' => false,
  56.             ));
  57.     }
  58.     public function configureOptions(OptionsResolver $resolver): void
  59.     {
  60.         $resolver->setDefaults([
  61.             'data_class' => null,
  62.         ]);
  63.     }
  64. }