<?php
namespace App\Form;
use App\Data\ClassificationData;
use App\Data\SalutationData;
use App\Entity\User;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Validator\Constraints\Type;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('username', TextType::class, [
'label' => 'Benutzername',
'help' => 'Wir empfehlen, den Namen Ihrer Kommune als Benutzernamen festzulegen',
'constraints' => [
new NotBlank([
'message' => 'Bitte geben Sie einen Benutzernamen an'
])
]
])
->add('salutation', ChoiceType::class, [
'label' => 'Anrede',
// 'required' => false,
'choice_loader' => new CallbackChoiceLoader(function () {
return SalutationData::getOptions();
})
])
->add('title', TextType::class, [
'label' => 'Titel',
'required' => false,
])
->add('firstname', TextType::class, [
'label' => 'Vorname',
])
->add('lastname', TextType::class, [
'label' => 'Nachname',
])
->add('email', EmailType::class, [
'label' => 'E-Mail',
])
->add('contactAllowed', CheckboxType::class, [
'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'
])
->add('name', TextType::class, [
'mapped' => false,
'label' => 'Name der Kommune',
'constraints' => [
new NotBlank([
'message' => 'Bitte geben Sie den Namen der Kommune an'
])
]
])
->add('zipcode', TextType::class, [
'mapped' => false,
'label' => 'Postleitzahl (Kommune)',
'attr' => ['maxlength' => 5],
'constraints' => [
new Length([
'allowEmptyString' => false,
'min' => 5,
'minMessage' => 'Bitte geben Sie eine gültige Postleitzahl an',
// 'max' => 5,
// 'maxMessage' => 'Bitte geben Sie eine gültige Postleitzahl an',
]),
// new Type('integer'),
new Regex(array(
'pattern' => '/^[0-9]\d*$/',
'message' => 'Bitte geben Sie eine gültige Postleitzahl an'
)
),
new NotBlank([
'message' => 'Bitte geben Sie eine Postleitzahl an'
])
]
])
->add('federalstate', EntityType::class, [
'mapped' => false,
'label' => 'Bundesland',
'class' => \App\Entity\FederalState::class,
'choice_label' => 'name',
'error_bubbling' => false,
'placeholder' => 'Bitte wählen',
// 'choice_loader' => new CallbackChoiceLoader(function() {
// return Federalstate::getOptions();
// }),
'constraints' => [
new NotBlank([
'message' => 'Bitte wählen Sie ein Bundesland'
])
]
])
->add('classification', ChoiceType::class, [
'mapped' => false,
'label' => 'Klassifizierung',
'placeholder' => 'Bitte wählen',
'choice_loader' => new CallbackChoiceLoader(function() {
return ClassificationData::getOptions();
}),
'constraints' => [
new NotBlank([
'message' => 'Bitte nehmen Sie eine Klassifizierung vor'
])
]
])
->add('classificationAlt', TextType::class, [
'mapped' => false,
'label' => 'weitere Angabe bei Auswahl \'Sonstige\'',
'required' => false,
])
// ->add('plainPassword', PasswordType::class, [
// // instead of being set onto the object directly,
// // this is read and encoded in the controller
// 'mapped' => false,
// 'attr' => ['autocomplete' => 'new-password'],
// 'constraints' => [
// new NotBlank([
// 'message' => 'Bitte geben Sie ein Passwort ein',
// ]),
// new Length([
// 'min' => 6,
// 'minMessage' => 'Ihr Passwort muss mindestens {{ limit }} Zeichen enthalten',
// // max length allowed by Symfony for security reasons
// 'max' => 4096,
// ]),
// ],
// ])
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => [
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'Bitte geben Sie ein Passwort ein',
]),
new Length([
'min' => 6,
'minMessage' => 'Ihr Passwort muss mindestens {{ limit }} Zeichen haben',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
'label' => 'Passwort',
],
'second_options' => [
'attr' => ['autocomplete' => 'new-password'],
'label' => 'Passwort (Wiederholung)',
],
'invalid_message' => 'Die Passwörter stimmen nicht überein',
// Instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}