<?php
namespace App\Form\Einsendung;
use App\Entity\Einsendung\Leserbrief;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
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 LeserbriefType extends AbstractType
{
public function __construct(private readonly RouterInterface $router)
{
}
#[\Override]
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('thema', null, [
'label_attr' => ['class' => 'titel-label-fett'],
'required' => true,
'constraints' => [
new NotBlank(),
new Length(['max' => 100]),
],
])
->add('titel', null, [
'required' => true,
'constraints' => [
new NotBlank(),
new Length(['max' => 100]),
],
])
->add('text', TextareaType::class,
[
'required' => true,
'attr' => ['maxlength' => 2000, 'placeholder' => 'Max. 2000 Zeichen, inkl. Leerschläge'],
'constraints' => [
new NotBlank(),
new Length(['max' => 2000]),
],
]
)
->add('bemerkungen', TextareaType::class,
[
'required' => false,
'attr' => ['maxlength' => 1000],
'constraints' => [
new Length(['max' => 1000]),
],
'help' => '(z.B. Ich nehme Bezug auf ein Thema/Leserbrief vom ...)',
]
)
->add('disclaimer', CheckboxType::class,
[
'required' => true,
'mapped' => false,
'label' => '<a href="'.$this->router->generate('fe.page_einsendungen').'" target="_blank">Forumsregeln</a> gelesen und damit einverstanden',
'label_html' => true,
'constraints' => [
new NotBlank(),
],
]
)
// Kontakt
->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(),
],
]
)
->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' => Leserbrief::class,
'attr' => [
'novalidate' => 'novalidate',
'autocomplete' => 'off'
],
]);
}
}