src/Infrastructure/Form/Security/LoginType.php line 68

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Infrastructure\Form\Security;
  4. use App\Domain\Common\Entity\Machine;
  5. use App\Domain\Common\Repository\CentreRepository;
  6. use App\Domain\Common\Repository\MachineRepository;
  7. use App\Domain\Security\DTO\SecurityDTO;
  8. use Symfony\Component\Form\AbstractType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. class LoginType extends AbstractType
  15. {
  16.     private CentreRepository $centreRepository;
  17.     /**
  18.      * @var MachineRepository
  19.      */
  20.     private MachineRepository $machineRepository;
  21.     public function __construct(
  22.         CentreRepository $centreRepository,
  23.         MachineRepository $machineRepository
  24.     )
  25.     {
  26.         $this->centreRepository $centreRepository;
  27.         $this->machineRepository $machineRepository;
  28.     }
  29.     public function buildForm(FormBuilderInterface $builder, array $options)
  30.     {
  31.         $builder
  32.             ->add('username'TextType::class, [
  33.                 'label' => 'Identifiant',
  34.                 'required' => true,
  35.                 'attr' => [
  36.                     'placeholder' => 'Identifiant...'
  37.                 ],
  38.             ])
  39.             ->add('password'PasswordType::class, [
  40.                 'label' => 'Mot de passe',
  41.                 'required' => true,
  42.                 'attr' => [
  43.                     'placeholder' => 'Mot de passe...',
  44.                 ],
  45.             ])
  46.             ->add('centre'ChoiceType::class, [
  47.                 'label' => 'Choix du centre',
  48.                 'choices' => $this->centreRepository->findAll(),
  49.                 'choice_value' => 'id',
  50.                 'choice_label' => 'libelle',
  51.                 'attr' => [
  52.                     'class' => 'js-boxList-centre',
  53.                 ],
  54.             ])
  55.             ->add('machine'ChoiceType::class, [
  56.                 'label' => 'Choix de la machine',
  57.                 'choices' => $this->machineRepository->findAll(),
  58.                 'required' => false,
  59.                 'placeholder' => Machine::MACHINE_PLACEHOLDER,
  60.                 'choice_value' => 'id',
  61.                 'choice_label' => 'libelle',
  62.                 'choice_attr' => fn(Machine $machine) => [
  63.                     'data-centre' => $machine->getCentre()->getId(),
  64.                 ],
  65.                 'attr' => [
  66.                     'class' => 'js-boxList-machine'
  67.                 ],
  68.             ]);
  69.     }
  70.     public function configureOptions(OptionsResolver $resolver)
  71.     {
  72.         $resolver->setDefaults([
  73.             'data_class' => SecurityDTO::class,
  74.             'label' => 'connexion à l\'application',
  75.         ]);
  76.     }
  77. }