<?php
namespace App\Form\InserateFormular;
use App\Entity\InseratFormular\Kleininserat;
use Symfony\Component\Asset\Packages;
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\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 KleinInseratType extends AbstractType
{
public function __construct(
private readonly RouterInterface $router,
private readonly Packages $assetManager
)
{
}
#[\Override]
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('text', TextareaType::class, [
'required' => true,
'attr' => ['maxlength' => 250, 'placeholder' => 'Max. 250 Zeichen, inkl. Leerschläge'],
'constraints' => [
new NotBlank(),
new Length(['max' => 250]),
],
])
->add('date', DateType::class, [
'widget' => 'single_text',
'format' => 'dd.MM.yyyy',
'attr' => ['placeholder' => 'TT.MM.JJJJ', 'class' => 'jqDateTimePickerDate'],
'html5' => false,
'label_html' => true,
'label' => 'Erscheinungs-<br>datum',
'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('bezahlung', CheckboxType::class, [
'mapped' => false,
'required' => true,
'label' => 'Ich zahle den Betrag von CHF 10.- mit <a href="' . $this->assetManager->getUrl('bundles/app/frontend/download/Twint_QR_Code.pdf') . '" target="_blank">Twint</a>.',
'label_html' => true,
'constraints' => [
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' => Kleininserat::class,
'attr' => ['novalidate' => 'novalidate'],
]);
}
}