src/Form/Einsendung/LeserbriefType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form\Einsendung;
  3. use App\Entity\Einsendung\Leserbrief;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Routing\RouterInterface;
  11. use Symfony\Component\Validator\Constraints\Length;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. class LeserbriefType extends AbstractType
  14. {
  15. public function __construct(private readonly RouterInterface $router)
  16. {
  17. }
  18. #[\Override]
  19. public function buildForm(FormBuilderInterface $builder, array $options): void
  20. {
  21. $builder
  22. ->add('thema', null, [
  23. 'label_attr' => ['class' => 'titel-label-fett'],
  24. 'required' => true,
  25. 'constraints' => [
  26. new NotBlank(),
  27. new Length(['max' => 100]),
  28. ],
  29. ])
  30. ->add('titel', null, [
  31. 'required' => true,
  32. 'constraints' => [
  33. new NotBlank(),
  34. new Length(['max' => 100]),
  35. ],
  36. ])
  37. ->add('text', TextareaType::class,
  38. [
  39. 'required' => true,
  40. 'attr' => ['maxlength' => 2000, 'placeholder' => 'Max. 2000 Zeichen, inkl. Leerschläge'],
  41. 'constraints' => [
  42. new NotBlank(),
  43. new Length(['max' => 2000]),
  44. ],
  45. ]
  46. )
  47. ->add('bemerkungen', TextareaType::class,
  48. [
  49. 'required' => false,
  50. 'attr' => ['maxlength' => 1000],
  51. 'constraints' => [
  52. new Length(['max' => 1000]),
  53. ],
  54. 'help' => '(z.B. Ich nehme Bezug auf ein Thema/Leserbrief vom ...)',
  55. ]
  56. )
  57. ->add('disclaimer', CheckboxType::class,
  58. [
  59. 'required' => true,
  60. 'mapped' => false,
  61. 'label' => '<a href="'.$this->router->generate('fe.page_einsendungen').'" target="_blank">Forumsregeln</a> gelesen und damit einverstanden',
  62. 'label_html' => true,
  63. 'constraints' => [
  64. new NotBlank(),
  65. ],
  66. ]
  67. )
  68. // Kontakt
  69. ->add('vorname', TextType::class,
  70. [
  71. 'required' => true,
  72. 'attr' => ['maxlength' => 100],
  73. 'constraints' => [
  74. new Length(['max' => 100]),
  75. new NotBlank(),
  76. ],
  77. ]
  78. )
  79. ->add('nachname', TextType::class,
  80. [
  81. 'required' => true,
  82. 'label' => 'Name',
  83. 'attr' => ['maxlength' => 100],
  84. 'constraints' => [
  85. new Length(['max' => 100]),
  86. new NotBlank(),
  87. ],
  88. ]
  89. )
  90. ->add('strasse', TextType::class,
  91. [
  92. 'required' => true,
  93. 'attr' => ['maxlength' => 100],
  94. 'constraints' => [
  95. new Length(['max' => 100]),
  96. new NotBlank(),
  97. ],
  98. 'label' => 'Strasse/Nr.'
  99. ]
  100. )
  101. ->add('plz', TextType::class,
  102. [
  103. 'label' => 'PLZ',
  104. 'required' => true,
  105. 'attr' => ['maxlength' => 100],
  106. 'constraints' => [
  107. new Length(['max' => 100]),
  108. new NotBlank(),
  109. ],
  110. ]
  111. )
  112. ->add('ort', TextType::class,
  113. [
  114. 'required' => true,
  115. 'attr' => ['maxlength' => 100],
  116. 'constraints' => [
  117. new Length(['max' => 100]),
  118. new NotBlank(),
  119. ],
  120. ]
  121. )
  122. ->add('telefon', TextType::class,
  123. [
  124. 'required' => true,
  125. 'attr' => ['maxlength' => 100],
  126. 'constraints' => [
  127. new Length(['max' => 100]),
  128. new NotBlank(),
  129. ],
  130. ]
  131. )
  132. ->add('email', TextType::class,
  133. [
  134. 'label' => 'E-Mail',
  135. 'required' => true,
  136. 'attr' => ['maxlength' => 100],
  137. 'constraints' => [
  138. new Length(['max' => 100]),
  139. new NotBlank(),
  140. ],
  141. ]
  142. )
  143. ->add('datenschutz', CheckboxType::class,
  144. [
  145. 'mapped' => false,
  146. 'required' => true,
  147. 'label' => 'Ich habe die <a href="'.$this->router->generate('fe.page_datenschutz').'" target="_blank">Datenschutzrichtlinien</a> gelesen und bin damit einverstanden.',
  148. 'label_html' => true,
  149. 'constraints' => [
  150. new NotBlank(),
  151. ],
  152. ]
  153. )
  154. ;
  155. }
  156. #[\Override]
  157. public function configureOptions(OptionsResolver $resolver): void
  158. {
  159. $resolver->setDefaults([
  160. 'data_class' => Leserbrief::class,
  161. 'attr' => [
  162. 'novalidate' => 'novalidate',
  163. 'autocomplete' => 'off'
  164. ],
  165. ]);
  166. }
  167. }