1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add(articles', EntityType::class, [
'class' => Articles::class,
'choice_label' => titre,
'choice_filter' => ChoiceList::filter(
$this,
function ($articles) {
if ($articles instanceof Articles) {
// cette ligne seul fonctionne, avec ID seulement: return in_array($articles->getID(), [1, 2]);
$entityManager = $this->em;
$query = $entityManager->createQuery(
'SELECT a.name
FROM
App\Entity\Articles a
WHERE a.category = 1
OR a.category = 2
'
);
return $query->getResult();
}
return false;
}, 'articles'
),
'autocomplete' => true,
])
->add('comment')
;
} |
Partager