src/Form/InserateFormular/AnschlagbrettType.php line 21

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