1

I want to get customize choices from a FormType

This is is the FormType:

builder->add('demandes', EntityType::class, [
            'placeholder' => 'Choisissez une option',
            'class'    => DemandeCandidats::class,
            'mapped' => false,
        ])

And this the repository

public function findActif($value)
{
    return $this->createQueryBuilder('d')
        ->andWhere('d.etat = :val')
        ->setParameter('val', "actif")
        ->getQuery()
        ->getResult()
    ;
}

How to add this repository to EntityType ?

Khalil
  • 288
  • 3
  • 16
  • 1
    Read about it here https://symfony.com/doc/current/reference/forms/types/entity.html#using-a-custom-query-for-the-entities – Fabian Schmick Mar 18 '19 at 15:01

1 Answers1

2
builder->add('demandes', EntityType::class, [
            'placeholder' => 'Choisissez une option',
            'class'    => DemandeCandidats::class,
            'mapped' => false,
            'query_builder' => function(EntityTypeRepository $er) {
                    return $er->createQueryBuilder('d')
                           ->andWhere('d.etat = :val')
                           ->setParameter('val', "actif")
                           ->getQuery()
                           ->getResult();
                    },
        ])

Or

builder->add('demandes', EntityType::class, [
            'placeholder' => 'Choisissez une option',
            'class'    => DemandeCandidats::class,
            'mapped' => false,
            'query_builder' => function(EntityTypeRepository $er) {
                    return $er->findActif("actif");
                    },
        ])
AythaNzt
  • 1,057
  • 6
  • 14