<?php
namespace App\Form\Einsendung;
use App\Entity\Einsendung\Nachruf;
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\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
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 NachrufType extends AbstractType
{
public function __construct(private readonly RouterInterface $router)
{
}
#[\Override]
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$geburtsjahre = [];
for ($i = date('Y') - 100; $i <= date('Y'); ++$i) {
$geburtsjahre[$i] = $i;
}
$todesjahre = [];
for ($i = date('Y'); $i >= date('Y') - 10; --$i) {
$todesjahre[$i] = $i;
}
$builder
->add('vVorname', null, [
'label' => 'Vorname',
'attr' => ['placeholder' => 'der verstorbenen Person'],
'required' => true,
'constraints' => [
new NotBlank(),
new Length(['max' => 100]),
],
])
->add('vNachname', null, [
'label' => 'Name',
'attr' => ['placeholder' => 'der verstorbenen Person'],
'required' => true,
'constraints' => [
new NotBlank(),
new Length(['max' => 100]),
],
])
->add('geburtsjahr', ChoiceType::class, [
'required' => true,
'placeholder' => '',
'choices' => $geburtsjahre,
'constraints' => [
new NotBlank(),
new Length(['max' => 100]),
],
])
->add('todesjahr', ChoiceType::class, [
'required' => true,
'placeholder' => '',
'choices' => $todesjahre,
'constraints' => [
new NotBlank(),
new Length(['max' => 100]),
],
])
->add('text', TextareaType::class,
[
'required' => true,
'attr' => ['maxlength' => 6000, 'placeholder' => 'Max. 6000 Zeichen, inkl. Leerschläge'],
'constraints' => [
new NotBlank(),
new Length(['max' => 6000]),
],
]
)
->add('wunschdatum', DateType::class, [
'widget' => 'single_text',
'format' => 'dd.MM.yyyy',
'attr' => ['placeholder' => 'TT.MM.JJJJ', 'class' => 'jqDateTimePickerDate'],
'html5' => false,
])
->add('bemerkungen', TextareaType::class,
[
'required' => false,
'attr' => ['maxlength' => 1000],
'constraints' => [
new Length(['max' => 1000]),
],
]
)
// 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(),
],
]
)
// Image
->add('imageFilepath', HiddenType::class, ['label' => 'Bild', '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('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' => Nachruf::class,
'attr' => [
'novalidate' => 'novalidate',
'autocomplete' => 'off'
],
]);
}
}