src/Form/RegistrationFormType.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Data\ClassificationData;
  4. use App\Data\SalutationData;
  5. use App\Entity\User;
  6. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
  9. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  12. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  13. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. use Symfony\Component\Validator\Constraints\IsTrue;
  18. use Symfony\Component\Validator\Constraints\Length;
  19. use Symfony\Component\Validator\Constraints\NotBlank;
  20. use Symfony\Component\Validator\Constraints\Regex;
  21. use Symfony\Component\Validator\Constraints\Type;
  22. class RegistrationFormType extends AbstractType
  23. {
  24.     public function buildForm(FormBuilderInterface $builder, array $options): void
  25.     {
  26.         $builder
  27.             ->add('username'TextType::class, [
  28.                 'label' => 'Benutzername',
  29.                 'help' => 'Wir empfehlen, den Namen Ihrer Kommune als Benutzernamen festzulegen',
  30.                 'constraints' => [
  31.                     new NotBlank([
  32.                         'message' => 'Bitte geben Sie einen Benutzernamen an'
  33.                     ])
  34.                 ]
  35.             ])
  36.             ->add('salutation'ChoiceType::class, [
  37.                 'label' => 'Anrede',
  38. //                'required' => false,
  39.                 'choice_loader' => new CallbackChoiceLoader(function () {
  40.                     return SalutationData::getOptions();
  41.                 })
  42.             ])
  43.             ->add('title'TextType::class, [
  44.                 'label' => 'Titel',
  45.                 'required' => false,
  46.             ])
  47.             ->add('firstname'TextType::class, [
  48.                 'label' => 'Vorname',
  49.             ])
  50.             ->add('lastname'TextType::class, [
  51.                 'label' => 'Nachname',
  52.             ])
  53.             ->add('email'EmailType::class, [
  54.                 'label' => 'E-Mail',
  55.             ])
  56.             ->add('contactAllowed'CheckboxType::class, [
  57.                 'label' => 'Ich bin damit einverstanden, dass ich seitens der Abteilung Fairer Handel und Faire Beschaffung von Engagement Global auch zu anderen Themen als zum Wettbewerb „Hauptstadt des Fairen Handels“ per E-Mail und Telefon kontaktiert werden kann'
  58.             ])
  59.             ->add('name'TextType::class, [
  60.                 'mapped' => false,
  61.                 'label' => 'Name der Kommune',
  62.                 'constraints' => [
  63.                     new NotBlank([
  64.                         'message' => 'Bitte geben Sie den Namen der Kommune an'
  65.                     ])
  66.                 ]
  67.             ])
  68.             ->add('zipcode'TextType::class, [
  69.                 'mapped' => false,
  70.                 'label' => 'Postleitzahl (Kommune)',
  71.                 'attr' => ['maxlength' => 5],
  72.                 'constraints' => [
  73.                     new Length([
  74.                         'allowEmptyString' => false,
  75.                         'min' => 5,
  76.                         'minMessage' => 'Bitte geben Sie eine gültige Postleitzahl an',
  77. //                        'max' => 5,
  78. //                        'maxMessage' => 'Bitte geben Sie eine gültige Postleitzahl an',
  79.                     ]),
  80. //                    new Type('integer'),
  81.                     new Regex(array(
  82.                             'pattern' => '/^[0-9]\d*$/',
  83.                             'message' => 'Bitte geben Sie eine gültige Postleitzahl an'
  84.                         )
  85.                     ),
  86.                     new NotBlank([
  87.                         'message' => 'Bitte geben Sie eine Postleitzahl an'
  88.                     ])
  89.                 ]
  90.             ])
  91.             ->add('federalstate'EntityType::class, [
  92.                 'mapped' => false,
  93.                 'label' => 'Bundesland',
  94.                 'class' => \App\Entity\FederalState::class,
  95.                 'choice_label' => 'name',
  96.                 'error_bubbling' => false,
  97.                 'placeholder' => 'Bitte wählen',
  98. //                'choice_loader' => new CallbackChoiceLoader(function() {
  99. //                    return Federalstate::getOptions();
  100. //                }),
  101.                 'constraints' => [
  102.                     new NotBlank([
  103.                         'message' => 'Bitte wählen Sie ein Bundesland'
  104.                     ])
  105.                 ]
  106.             ])
  107.             ->add('classification'ChoiceType::class, [
  108.                 'mapped' => false,
  109.                 'label' => 'Klassifizierung',
  110.                 'placeholder' => 'Bitte wählen',
  111.                 'choice_loader' => new CallbackChoiceLoader(function() {
  112.                     return ClassificationData::getOptions();
  113.                 }),
  114.                 'constraints' => [
  115.                     new NotBlank([
  116.                         'message' => 'Bitte nehmen Sie eine Klassifizierung vor'
  117.                     ])
  118.                 ]
  119.             ])
  120.             ->add('classificationAlt'TextType::class, [
  121.                 'mapped' => false,
  122.                 'label' => 'weitere Angabe bei Auswahl \'Sonstige\'',
  123.                 'required' => false,
  124.             ])
  125. //            ->add('plainPassword', PasswordType::class, [
  126. //                // instead of being set onto the object directly,
  127. //                // this is read and encoded in the controller
  128. //                'mapped' => false,
  129. //                'attr' => ['autocomplete' => 'new-password'],
  130. //                'constraints' => [
  131. //                    new NotBlank([
  132. //                        'message' => 'Bitte geben Sie ein Passwort ein',
  133. //                    ]),
  134. //                    new Length([
  135. //                        'min' => 6,
  136. //                        'minMessage' => 'Ihr Passwort muss mindestens {{ limit }} Zeichen enthalten',
  137. //                        // max length allowed by Symfony for security reasons
  138. //                        'max' => 4096,
  139. //                    ]),
  140. //                ],
  141. //            ])
  142.             ->add('plainPassword'RepeatedType::class, [
  143.                 'type' => PasswordType::class,
  144.                 'first_options' => [
  145.                     'attr' => ['autocomplete' => 'new-password'],
  146.                     'constraints' => [
  147.                         new NotBlank([
  148.                             'message' => 'Bitte geben Sie ein Passwort ein',
  149.                         ]),
  150.                         new Length([
  151.                             'min' => 6,
  152.                             'minMessage' => 'Ihr Passwort muss mindestens {{ limit }} Zeichen haben',
  153.                             // max length allowed by Symfony for security reasons
  154.                             'max' => 4096,
  155.                         ]),
  156.                     ],
  157.                     'label' => 'Passwort',
  158.                 ],
  159.                 'second_options' => [
  160.                     'attr' => ['autocomplete' => 'new-password'],
  161.                     'label' => 'Passwort (Wiederholung)',
  162.                 ],
  163.                 'invalid_message' => 'Die Passwörter stimmen nicht überein',
  164.                 // Instead of being set onto the object directly,
  165.                 // this is read and encoded in the controller
  166.                 'mapped' => false,
  167.             ])
  168.         ;
  169.     }
  170.     public function configureOptions(OptionsResolver $resolver): void
  171.     {
  172.         $resolver->setDefaults([
  173.             'data_class' => User::class,
  174.         ]);
  175.     }
  176. }