I'm quite new to Symfony and I have a specific question. I have a form for a job application where the applicant can choose competencies linked to categories.
Entities:
Application linked to Competence as many to many
Compentence linked to Category as Many to One
So in ApplicationType I have:
->add('competences', EntityType::class, array(
'class' => 'SanOffresBundle:Competence',
'label' => 'Compétences (sélectionnez-en autant que vous voulez)',
'choice_label' => 'nom',
'multiple' => true,
'expanded' => true,
'query_builder' => function (CompetenceRepository $er) {
return $er->createQueryBuilder('cc')
->orderBy('cc.nom', 'ASC');},
'group_by' => function($val, $key, $index) {
return $val->getCategorie()->getNom();},
))
With this code and variations I get:
'expanded' => false : a menu with competences sorted by category, but the categories are not in alphabetical order. This would be an acceptable alternative if the categories were sorted, but with more than 100 competences to choose from, it's not user friendly.
'expanded' => true : a list of competences checkboxes displayed grouped by categories, but the categories are not shown.
Would anybody have an idea?