I want to display my Categories tree sort by names. I have a CategoryType to create new Category entity and assignate it a parent Category with a select box. Here's my form type :
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class, array("required" => false));
$builder->add('parent', EntityType::class, array(
'class' => 'CAPShopAdminBundle:Category',
'choice_label' => 'selectBoxName',
'placeholder' => '-- Aucune --',
'required' => false,
'query_builder' => function(NestedTreeRepository $r) {
return $r->createQueryBuilder('c')
->orderBy('c.root, c.lvl, c.name', 'ASC');
}
));
$builder->add('save', SubmitType::class);
}
Here's the result :
I search this result :
Is it possible without PHP treatment, just with the good SQL query?