I have a Categories table, built with Tree architecture, using Doctrine Tree Extension and it looks something like this
id parent_id title lft lvl rgt root
864 (NULL) Movies 1 0 18 864
865 864 Packs 2 1 3 864
866 864 Dubbed 4 1 5 864
and visually like this:
Movies
|
|
|->Packs
|->Dubbed
now i want to generated form for adding reviews , and loading categories as dropdown list for each movie, so i have in my movie-review form-type-class
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name');
$builder->add('file');
$builder->add('cover');
$builder->add('category','entity', array('class'=>'Tracker\MembersBundle\Entity\Category', 'property'=>'title', ));
}
which generates a normal dropdown menu like this:
how can i configure my menu settings, so it generates a Tree-Like-dropdown select like this?
I'm not sure this is a good idea : users won't be able to type in their choice.
Haven't tested this solution, but it should work :
First, you can sort the three by root and lft value to display it properly, so add a query builder:
Then, you need to add a
getIndentedTitle
method to your entity:Finally, add a property option to your options when you build the form, to display the virtual property indentedTitle instead of title :
See : http://symfony.com/doc/current/reference/forms/types/entity.html