src/App/Form/Forms/Security/Profile/SchoolRoleType.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Form\Forms\Security\Profile;
  3. use App\Entity\System\School;
  4. use App\Form\Type\Select2EntityType;
  5. use Doctrine\ORM\EntityRepository;
  6. use Platform\SecurityBundle\Entity\Access\Role;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\NotNull;
  11. class SchoolRoleType extends AbstractType
  12. {
  13.     /**
  14.      * {@inheritdoc}
  15.      */
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         $builder
  19.             ->add('school'Select2EntityType::class, [
  20.                 'required' => false,
  21.                 'label_tooltip' => true,
  22.                 'placeholder' => '[Global]',
  23.                 'class' => School::class,
  24.                 'empty_data' => null,
  25.                 'choice_label' => 'name',
  26.                 'query_builder' => function (EntityRepository $repo) {
  27.                     return $repo
  28.                         ->createQueryBuilder('school')
  29.                         ->addOrderBy('school.name''ASC');
  30.                 },
  31.             ]);
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public function configureOptions(OptionsResolver $resolver): void
  37.     {
  38.         $resolver->setDefaults([
  39.             'class' => Role\NotificationRole::class,
  40.         ]);
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function getParent(): string
  46.     {
  47.         return RoleType::class;
  48.     }
  49. }