Answer the question
In order to leave comments, you need to log in
How to remove one of the elements in the form combobox?
Greetings.
There is an entity
class Category
{
...
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var Category
* @ORM\ManyToOne(targetEntity="Category", inversedBy="children", cascade={"persist"})
* @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/
private $parent;
...
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'label' => "Категория",
])
->add('parent', EntityType::class, [
'label' => "Родительская категория",
"class" => Category::class,
"choice_label" => "name",
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.parent != :category')
->setParameter('category', ???);
}
]);
}
public function editAction(Request $request, Category $category)
{
$editForm = $this->createForm('MyBundle\Form\CategoryType', $category);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
...
}
return $this->render...
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question