src/Form/RegistrationType.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  5. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  6. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  7. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. class RegistrationType extends AbstractType
  11. {
  12.     /**
  13.      * {@inheritdoc}
  14.      */
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $builder->add('email'EmailType::class)
  18.             ->add('username');
  19.         if ($options['edit']) {
  20.             $builder->add('plainPassword'RepeatedType::class, [
  21.                 'type' => PasswordType::class,
  22.                 'required' => false,
  23.                 'invalid_message' => 'Passwords do not match',
  24.                 'first_options' => [
  25.                     'label' => 'Password',
  26.                     'attr' => ['class' => 'form-control'],
  27.                 ],
  28.                 'second_options' => [
  29.                     'label' => 'Password (validation)',
  30.                     'attr' => ['class' => 'form-control'],
  31.                 ]
  32.             ]);
  33.         } else {
  34.             $builder->add('plainPassword'RepeatedType::class, [
  35.                 'type' => PasswordType::class,
  36.                 'invalid_message' => 'Passwords do not match',
  37.                 'first_options' => [
  38.                     'label' => 'Password',
  39.                     'attr' => ['class' => 'form-control'],
  40.                 ],
  41.                 'second_options' => [
  42.                     'label' => 'Password (validation)',
  43.                     'attr' => ['class' => 'form-control'],
  44.                 ]
  45.             ]);
  46.         }
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function configureOptions(OptionsResolver $resolver)
  52.     {
  53.         $resolver->setDefaults(array(
  54.             'translation_domain' => 'admin',
  55.             'data_class' => 'App\Entity\User',
  56.             'edit' => false
  57.         ));
  58.     }
  59.     /**
  60.      * {@inheritdoc}
  61.      */
  62.     public function getBlockPrefix()
  63.     {
  64.         return 'userbundle_registration';
  65.     }
  66. }