<?php
namespace App\Form\Einsendung;
use App\Entity\Einsendung\Vereinsbeitrag;
use App\Entity\Vs\Vs;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
class VereinsbeitragType extends AbstractType
{
public function __construct(private readonly RouterInterface $router)
{
}
#[\Override]
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('titel', null, [
'required' => true,
'constraints' => [
new NotBlank(),
new Length(['max' => 100]),
],
])
->add('text', TextareaType::class,
[
'required' => true,
'attr' => ['maxlength' => 3000, 'placeholder' => 'Max. 3000 Zeichen, inkl. Leerschläge'],
'constraints' => [
new NotBlank(),
new Length(['max' => 3000]),
],
]
)
->add('bemerkungen', TextareaType::class,
[
'required' => false,
'attr' => ['maxlength' => 1000],
'constraints' => [
new Length(['max' => 1000]),
],
]
)
// Kontakt
->add('firma', TextType::class,
[
'required' => true,
'label' => 'Vereinsname',
'attr' => ['maxlength' => 100, 'placeholder' => 'Vereinsname / Organisation'],
'constraints' => [
new Length(['max' => 100]),
new NotBlank(),
],
]
)
->add('vorname', TextType::class,
[
'required' => true,
'attr' => ['maxlength' => 100],
'constraints' => [
new Length(['max' => 100]),
new NotBlank(),
],
]
)
->add('nachname', TextType::class,
[
'required' => true,
'label' => 'Name',
'attr' => ['maxlength' => 100],
'constraints' => [
new Length(['max' => 100]),
new NotBlank(),
],
]
)
->add('strasse', TextType::class,
[
'required' => true,
'attr' => ['maxlength' => 100],
'constraints' => [
new Length(['max' => 100]),
new NotBlank(),
],
'label' => 'Strasse/Nr.'
]
)
->add('plz', TextType::class,
[
'label' => 'PLZ',
'required' => true,
'attr' => ['maxlength' => 100],
'constraints' => [
new Length(['max' => 100]),
new NotBlank(),
],
]
)
->add('ort', TextType::class,
[
'required' => true,
'attr' => ['maxlength' => 100],
'constraints' => [
new Length(['max' => 100]),
new NotBlank(),
],
]
)
->add('telefon', TextType::class,
[
'required' => true,
'attr' => ['maxlength' => 100],
'constraints' => [
new Length(['max' => 100]),
new NotBlank(),
],
]
)
->add('email', TextType::class,
[
'label' => 'E-Mail',
'required' => true,
'attr' => ['maxlength' => 100],
'constraints' => [
new Length(['max' => 100]),
new NotBlank(),
],
]
)
// Image
->add('imageFilepath', HiddenType::class, ['label' => 'Bild 1', 'required' => false, 'mapped' => true, 'help' => 'max. 5 MB'])
->add('imageAlt', TextType::class, ['label' => 'Bild Alt', 'required' => false, 'mapped' => false, 'attr' => ['placeholder' => 'Bildbeschreibung (alt-Tag)']])
->add('imageCaption', TextType::class, ['label' => 'Bild Caption', 'mapped' => false, 'help' => 'Bild wird automatisch auf '.Vs::MAX_WIDTH_VSIMAGE.'px Breite runtergerechnet falls grösser.', 'required' => false, 'attr' => ['placeholder' => 'Bildlegende (figcaption-Tag)']])
->add('imageFilepath2', HiddenType::class, ['label' => 'Bild 2', 'required' => false, 'mapped' => true, 'help' => 'max. 5 MB'])
->add('imageAlt2', TextType::class, ['label' => 'Bild Alt', 'required' => false, 'mapped' => false, 'attr' => ['placeholder' => 'Bildbeschreibung (alt-Tag)']])
->add('imageCaption2', TextType::class, ['label' => 'Bild Caption', 'mapped' => false, 'help' => 'Bild wird automatisch auf '.Vs::MAX_WIDTH_VSIMAGE.'px Breite runtergerechnet falls grösser.', 'required' => false, 'attr' => ['placeholder' => 'Bildlegende (figcaption-Tag)']])
->add('bildLegende', TextType::class,
[
'required' => false,
'constraints' => [
new Length(['max' => 250]),
],
'label' => 'Bildlegende',
'attr' => [
'maxlength' => 250,
'placeholder' => 'Beschreibung für Bild 1',
],
]
)
->add('bildLegende2', TextType::class,
[
'required' => false,
'constraints' => [
new Length(['max' => 250]),
],
'label' => 'Bildlegende',
'attr' => [
'maxlength' => 250,
'placeholder' => 'Beschreibung für Bild 2',
],
]
)
->add('datenschutz', CheckboxType::class,
[
'mapped' => false,
'required' => true,
'label' => 'Ich habe die <a href="'.$this->router->generate('fe.page_datenschutz').'" target="_blank">Datenschutzrichtlinien</a> gelesen und bin damit einverstanden.',
'label_html' => true,
'constraints' => [
new NotBlank(),
],
]
)
;
}
#[\Override]
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Vereinsbeitrag::class,
'attr' => [
'novalidate' => 'novalidate',
'autocomplete' => 'off'
],
]);
}
}