src/Form/Type/LoginFormType.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  5. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  6. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  7. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\NotBlank;
  11. class LoginFormType extends AbstractType
  12. {
  13.     public function buildForm(FormBuilderInterface $builder, array $options): void
  14.     {
  15.         $builder
  16.             ->add('_username'null, [
  17.                 'label'       => 'members.auth.login.username',
  18.                 'constraints' => [new NotBlank()],
  19.                 'data'        => $options['last_username']
  20.             ])
  21.             ->add('_password'PasswordType::class, [
  22.                 'label'       => 'members.auth.login.password',
  23.                 'constraints' => [new NotBlank()],
  24.             ])
  25.             ->add('_remember_me'CheckboxType::class, [
  26.                 'label'    => 'members.auth.login.remember_me',
  27.                 'required' => false
  28.             ])
  29.             ->add('_submit'SubmitType::class, [
  30.                 'label' => 'members.auth.login.submit'
  31.             ]);
  32.         if ($options['_target_path'] !== null) {
  33.             $builder->add(
  34.                 '_target_path',
  35.                 HiddenType::class,
  36.                 ['data' => $options['_target_path']]
  37.             );
  38.         }
  39.         if ($options['_failure_path'] !== null) {
  40.             $builder->add(
  41.                 '_failure_path',
  42.                 HiddenType::class,
  43.                 ['data' => $options['_failure_path']]
  44.             );
  45.         }
  46.     }
  47.     public function configureOptions(OptionsResolver $resolver): void
  48.     {
  49.         $resolver->setDefaults([
  50.             'csrf_token_id'   => 'authenticate',
  51.             'csrf_field_name' => '_csrf_token',
  52.             'last_username'   => null,
  53.             '_target_path'    => null,
  54.             '_failure_path'   => null,
  55.         ]);
  56.     }
  57.     public function getBlockPrefix(): string
  58.     {
  59.         return 'members_user_login';
  60.     }
  61. }