src/Form/InserateFormular/KleinInseratType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form\InserateFormular;
  3. use App\Entity\InseratFormular\Kleininserat;
  4. use Symfony\Component\Asset\Packages;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\DateType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Routing\RouterInterface;
  14. use Symfony\Component\Validator\Constraints\Length;
  15. use Symfony\Component\Validator\Constraints\NotBlank;
  16. class KleinInseratType extends AbstractType
  17. {
  18. public function __construct(
  19. private readonly RouterInterface $router,
  20. private readonly Packages $assetManager
  21. )
  22. {
  23. }
  24. #[\Override]
  25. public function buildForm(FormBuilderInterface $builder, array $options): void
  26. {
  27. $builder
  28. ->add('text', TextareaType::class, [
  29. 'required' => true,
  30. 'attr' => ['maxlength' => 250, 'placeholder' => 'Max. 250 Zeichen, inkl. Leerschläge'],
  31. 'constraints' => [
  32. new NotBlank(),
  33. new Length(['max' => 250]),
  34. ],
  35. ])
  36. ->add('date', DateType::class, [
  37. 'widget' => 'single_text',
  38. 'format' => 'dd.MM.yyyy',
  39. 'attr' => ['placeholder' => 'TT.MM.JJJJ', 'class' => 'jqDateTimePickerDate'],
  40. 'html5' => false,
  41. 'label_html' => true,
  42. 'label' => 'Erscheinungs-<br>datum',
  43. 'constraints' => [
  44. new NotBlank(),
  45. ]
  46. ])
  47. // Kontakt
  48. ->add('vorname', TextType::class, [
  49. 'required' => true,
  50. 'attr' => ['maxlength' => 100],
  51. 'constraints' => [
  52. new Length(['max' => 100]),
  53. new NotBlank(),
  54. ],
  55. ])
  56. ->add('nachname', TextType::class, [
  57. 'required' => true,
  58. 'label' => 'Name',
  59. 'attr' => ['maxlength' => 100],
  60. 'constraints' => [
  61. new Length(['max' => 100]),
  62. new NotBlank(),
  63. ],
  64. ])
  65. ->add('strasse', TextType::class, [
  66. 'required' => true,
  67. 'attr' => ['maxlength' => 100],
  68. 'constraints' => [
  69. new Length(['max' => 100]),
  70. new NotBlank(),
  71. ],
  72. 'label' => 'Strasse/Nr.'
  73. ])
  74. ->add('plz', TextType::class, [
  75. 'label' => 'PLZ',
  76. 'required' => true,
  77. 'attr' => ['maxlength' => 100],
  78. 'constraints' => [
  79. new Length(['max' => 100]),
  80. new NotBlank(),
  81. ],
  82. ])
  83. ->add('ort', TextType::class, [
  84. 'required' => true,
  85. 'attr' => ['maxlength' => 100],
  86. 'constraints' => [
  87. new Length(['max' => 100]),
  88. new NotBlank(),
  89. ],
  90. ])
  91. ->add('telefon', TextType::class,
  92. [
  93. 'required' => true,
  94. 'attr' => ['maxlength' => 100],
  95. 'constraints' => [
  96. new Length(['max' => 100]),
  97. new NotBlank(),
  98. ],
  99. ])
  100. ->add('email', TextType::class, [
  101. 'label' => 'E-Mail',
  102. 'required' => true,
  103. 'attr' => ['maxlength' => 100],
  104. 'constraints' => [
  105. new Length(['max' => 100]),
  106. new NotBlank(),
  107. ],
  108. ])
  109. ->add('bezahlung', CheckboxType::class, [
  110. 'mapped' => false,
  111. 'required' => true,
  112. '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>.',
  113. 'label_html' => true,
  114. 'constraints' => [
  115. new NotBlank(),
  116. ],
  117. ])
  118. ->add('datenschutz', CheckboxType::class, [
  119. 'mapped' => false,
  120. 'required' => true,
  121. 'label' => 'Ich habe die <a href="' . $this->router->generate('fe.page_datenschutz') . '" target="_blank">Datenschutzrichtlinien</a> gelesen und bin damit einverstanden.',
  122. 'label_html' => true,
  123. 'constraints' => [
  124. new NotBlank(),
  125. ],
  126. ]);
  127. }
  128. #[\Override]
  129. public function configureOptions(OptionsResolver $resolver): void
  130. {
  131. $resolver->setDefaults([
  132. 'data_class' => Kleininserat::class,
  133. 'attr' => ['novalidate' => 'novalidate'],
  134. ]);
  135. }
  136. }