Answer the question
In order to leave comments, you need to log in
How to exclude query_builder in Symfony2 buildForm?
$builder
->add(
'maker',
'entity',
array(
'class' => 'CrbrBundle:CrbrItemMaker',
'property' => 'name',
'required' => false,
'data' => $options['maker'],
'empty_value' => '-- Все --',
'query_builder' => function (EntityRepository $er) use ($options) {
return $er->createQueryBuilder('x')
->innerJoin('x.item', 'i')
->innerJoin('i.category', 'c')
->innerJoin('c.parentCategory', 'h')
->andWhere('h.categoryGroup = :groupCategory')
->setParameter(
'groupCategory',
$options['groupCategory']
);
}
,
)
)
Answer the question
In order to leave comments, you need to log in
Make the form without the `marker` field, and add it on the FormEvents::PRE_SET_DATA event when the necessary conditions match.
See symfony.com/doc/current/cookbook/form/dynamic_form...
'query_builder' => function (EntityRepository $er) use ($options) {
if ($options['groupCategory'] == 3) {
return $er->createQueryBuilder('x');
}
return $er->createQueryBuilder('x')
->innerJoin('x.item', 'i')
->innerJoin('i.category', 'c')
->innerJoin('c.parentCategory', 'h')
->andWhere('h.categoryGroup = :groupCategory')
->setParameter(
'groupCategory',
$options['groupCategory']
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question