src/Form/Einsendung/NachrufType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form\Einsendung;
  3. use App\Entity\Einsendung\Nachruf;
  4. use App\Entity\Vs\Vs;
  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\HiddenType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Routing\RouterInterface;
  15. use Symfony\Component\Validator\Constraints\Length;
  16. use Symfony\Component\Validator\Constraints\NotBlank;
  17. class NachrufType extends AbstractType
  18. {
  19. public function __construct(private readonly RouterInterface $router)
  20. {
  21. }
  22. #[\Override]
  23. public function buildForm(FormBuilderInterface $builder, array $options): void
  24. {
  25. $geburtsjahre = [];
  26. for ($i = date('Y') - 100; $i <= date('Y'); ++$i) {
  27. $geburtsjahre[$i] = $i;
  28. }
  29. $todesjahre = [];
  30. for ($i = date('Y'); $i >= date('Y') - 10; --$i) {
  31. $todesjahre[$i] = $i;
  32. }
  33. $builder
  34. ->add('vVorname', null, [
  35. 'label' => 'Vorname',
  36. 'attr' => ['placeholder' => 'der verstorbenen Person'],
  37. 'required' => true,
  38. 'constraints' => [
  39. new NotBlank(),
  40. new Length(['max' => 100]),
  41. ],
  42. ])
  43. ->add('vNachname', null, [
  44. 'label' => 'Name',
  45. 'attr' => ['placeholder' => 'der verstorbenen Person'],
  46. 'required' => true,
  47. 'constraints' => [
  48. new NotBlank(),
  49. new Length(['max' => 100]),
  50. ],
  51. ])
  52. ->add('geburtsjahr', ChoiceType::class, [
  53. 'required' => true,
  54. 'placeholder' => '',
  55. 'choices' => $geburtsjahre,
  56. 'constraints' => [
  57. new NotBlank(),
  58. new Length(['max' => 100]),
  59. ],
  60. ])
  61. ->add('todesjahr', ChoiceType::class, [
  62. 'required' => true,
  63. 'placeholder' => '',
  64. 'choices' => $todesjahre,
  65. 'constraints' => [
  66. new NotBlank(),
  67. new Length(['max' => 100]),
  68. ],
  69. ])
  70. ->add('text', TextareaType::class,
  71. [
  72. 'required' => true,
  73. 'attr' => ['maxlength' => 6000, 'placeholder' => 'Max. 6000 Zeichen, inkl. Leerschläge'],
  74. 'constraints' => [
  75. new NotBlank(),
  76. new Length(['max' => 6000]),
  77. ],
  78. ]
  79. )
  80. ->add('wunschdatum', DateType::class, [
  81. 'widget' => 'single_text',
  82. 'format' => 'dd.MM.yyyy',
  83. 'attr' => ['placeholder' => 'TT.MM.JJJJ', 'class' => 'jqDateTimePickerDate'],
  84. 'html5' => false,
  85. ])
  86. ->add('bemerkungen', TextareaType::class,
  87. [
  88. 'required' => false,
  89. 'attr' => ['maxlength' => 1000],
  90. 'constraints' => [
  91. new Length(['max' => 1000]),
  92. ],
  93. ]
  94. )
  95. // Kontakt
  96. ->add('vorname', TextType::class,
  97. [
  98. 'required' => true,
  99. 'attr' => ['maxlength' => 100],
  100. 'constraints' => [
  101. new Length(['max' => 100]),
  102. new NotBlank(),
  103. ],
  104. ]
  105. )
  106. ->add('nachname', TextType::class,
  107. [
  108. 'required' => true,
  109. 'label' => 'Name',
  110. 'attr' => ['maxlength' => 100],
  111. 'constraints' => [
  112. new Length(['max' => 100]),
  113. new NotBlank(),
  114. ],
  115. ]
  116. )
  117. ->add('strasse', TextType::class,
  118. [
  119. 'required' => true,
  120. 'attr' => ['maxlength' => 100],
  121. 'constraints' => [
  122. new Length(['max' => 100]),
  123. new NotBlank(),
  124. ],
  125. 'label' => 'Strasse/Nr.'
  126. ]
  127. )
  128. ->add('plz', TextType::class,
  129. [
  130. 'label' => 'PLZ',
  131. 'required' => true,
  132. 'attr' => ['maxlength' => 100],
  133. 'constraints' => [
  134. new Length(['max' => 100]),
  135. new NotBlank(),
  136. ],
  137. ]
  138. )
  139. ->add('ort', TextType::class,
  140. [
  141. 'required' => true,
  142. 'attr' => ['maxlength' => 100],
  143. 'constraints' => [
  144. new Length(['max' => 100]),
  145. new NotBlank(),
  146. ],
  147. ]
  148. )
  149. ->add('telefon', TextType::class,
  150. [
  151. 'required' => true,
  152. 'attr' => ['maxlength' => 100],
  153. 'constraints' => [
  154. new Length(['max' => 100]),
  155. new NotBlank(),
  156. ],
  157. ]
  158. )
  159. ->add('email', TextType::class,
  160. [
  161. 'label' => 'E-Mail',
  162. 'required' => true,
  163. 'attr' => ['maxlength' => 100],
  164. 'constraints' => [
  165. new Length(['max' => 100]),
  166. new NotBlank(),
  167. ],
  168. ]
  169. )
  170. // Image
  171. ->add('imageFilepath', HiddenType::class, ['label' => 'Bild', 'required' => false, 'mapped' => true, 'help' => 'max. 5 MB'])
  172. ->add('imageAlt', TextType::class, ['label' => 'Bild Alt', 'required' => false, 'mapped' => false, 'attr' => ['placeholder' => 'Bildbeschreibung (alt-Tag)']])
  173. ->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)']])
  174. ->add('datenschutz', CheckboxType::class,
  175. [
  176. 'mapped' => false,
  177. 'required' => true,
  178. 'label' => 'Ich habe die <a href="'.$this->router->generate('fe.page_datenschutz').'" target="_blank">Datenschutzrichtlinien</a> gelesen und bin damit einverstanden.',
  179. 'label_html' => true,
  180. 'constraints' => [
  181. new NotBlank(),
  182. ],
  183. ]
  184. )
  185. ;
  186. }
  187. #[\Override]
  188. public function configureOptions(OptionsResolver $resolver): void
  189. {
  190. $resolver->setDefaults([
  191. 'data_class' => Nachruf::class,
  192. 'attr' => [
  193. 'novalidate' => 'novalidate',
  194. 'autocomplete' => 'off'
  195. ],
  196. ]);
  197. }
  198. }