I want a choice list (dropdown) grouped by parent categories (not selectable). Is this even possible?
Example:
- Vehiculs (not selectable)
-- Car (selectable)
-- Boat (selectable)
- Computers (not selectable)
Entity Category
/**
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
**/
private $children;
/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
**/
private $parent;
Form:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', 'text',
[
'attr' => ['placeholder' => 'Titel', 'class' => 'form-control', 'autocomplete' => 'off'],
'label' => false
]
)
...
->add('category', 'entity',
[
'property' => 'name',
'class' => '***ArticleBundle:Category',
]
)
;
}
With the code above i only get the parents and they are selectable. I would like to group the children of those parents (1 depth) and make only the children selectable options.