order centers dropdown alphabetically

This commit is contained in:
Julie Lenaerts 2024-02-08 11:20:21 +01:00
parent f1fa4d415e
commit 2b968b9a5b

View File

@ -13,6 +13,7 @@ namespace Chill\MainBundle\Form\Type;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\PermissionsGroup; use Chill\MainBundle\Entity\PermissionsGroup;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -27,7 +28,13 @@ class ComposedGroupCenterType extends AbstractType
'choice_label' => static fn (PermissionsGroup $group) => $group->getName(), 'choice_label' => static fn (PermissionsGroup $group) => $group->getName(),
])->add('center', EntityType::class, [ ])->add('center', EntityType::class, [
'class' => Center::class, 'class' => Center::class,
'choice_label' => static fn (Center $center) => $center->getName(), 'query_builder' => static function (EntityRepository $er) {
$qb = $er->createQueryBuilder('c');
$qb->where($qb->expr()->eq('c.isActive', 'TRUE'))
->orderBy('c.name', 'ASC');
return $qb;
},
]); ]);
} }