src/Form/ClaimSachType.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Claim;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\FileType;
  10. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  11. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Component\Validator\Constraints\File;
  16. class ClaimSachType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options): void
  19.     {
  20.         $builder
  21.             ->add('department'null, [
  22.                 'label' => 'Dienststelle',
  23.                 'required' => true,
  24.                 'constraints' => [
  25.                     new Assert\NotBlank(),
  26.                 ],
  27.             ])
  28.             ->add('claimDate'null, [
  29.                 'label' => 'Wann hat sich das Schadenereignis zugetragen?',
  30.                 'required' => false,
  31.                 'years' => range(date('Y'), date('Y')-5),
  32.             ])
  33.             ->add('claimAddress'AddressBlockType::class, [
  34.                 'label' => "Schadenort",
  35.                 'required' => true,
  36.                 'constraints' => [
  37.                     new Assert\NotBlank(),
  38.                 ],
  39.             ])
  40.             ->add('claimDescription'null, [
  41.                 'label' => "Schadenshergang",
  42.                 'required' => true,
  43.                 'constraints' => [
  44.                     new Assert\NotBlank(),
  45.                 ],
  46.             ])
  47.             ->add('damageCosts'NumberType::class, [
  48.                 'scale' => 2,
  49.                 'label' => "Schadensumme",
  50.                 'required' => false,
  51.                 'constraints' => [
  52.                     new Assert\Range([
  53.                         'min' => 0,
  54.                         'max' => 9999999999999.99,
  55.                     ]),
  56.                 ],
  57.             ])
  58.             ->add('sachOwner'NameAddressBlockType::class, [
  59.                 'label' => "Wer ist der Eigentümer?",
  60.                 'required' => true,
  61.                 'constraints' => [
  62.                     new Assert\NotBlank(),
  63.                 ],
  64.             ])
  65.             ->add('damageBy'NameAddressBlockType::class, [
  66.                 'label' => "Wer hat den Schaden verursacht?",
  67.                 'required' => false,
  68.                 'constraints' => [
  69.                     new Assert\NotBlank(),
  70.                 ],
  71.             ])
  72.             ->add('policeReport'null, [
  73.                 'label' => "Schaden gemeldet bei (Polizei, Feuerwehr, ...)",
  74.                 'required' => true,
  75.             ])
  76.             ->add('policeReportDate'null, [
  77.                 'label' => "Datum der Anzeige",
  78.                 'required' => true,
  79.             ])
  80.             ->add('persons'CollectionType::class, [
  81.                 'label' => false,
  82.                 'entry_type' => PersonType::class,
  83.                 'entry_options' => [],
  84.                 'allow_add' => true,
  85.                 'allow_delete' => true,
  86.                 'by_reference' => false,
  87.                 'prototype' => true,
  88.                 'prototype_name' => '__item__',
  89.             ])
  90.             ->add('remark'null, [
  91.                 'label' => "Beschädigte Sachen / Weitere Angaben / Bemerkungen",
  92.                 'required' => false,
  93.             ])
  94.             ->add('name'null, [
  95.                 'label' => false,
  96.                 'required' => true,
  97.                 'constraints' => [
  98.                     new Assert\NotBlank(),
  99.                 ],
  100.                 'attr' => [
  101.                     'placeholder' => 'Name',
  102.                 ],
  103.             ])
  104.             ->add('email'EmailType::class, [
  105.                 'label' => false,
  106.                 'required' => true,
  107.                 'constraints' => [
  108.                     new Assert\NotBlank(),
  109.                     new Assert\Email(),
  110.                 ],
  111.                 'attr' => [
  112.                     'placeholder' => 'Email',
  113.                 ],
  114.             ])
  115.             ->add('ccEmail'EmailType::class, [
  116.                 'label' => false,
  117.                 'required' => false,
  118.                 'constraints' => [
  119.                     new Assert\Email(),
  120.                 ],
  121.                 'attr' => [
  122.                     'placeholder' => 'CC Email',
  123.                 ],
  124.             ])
  125.             ->add('claimFiles'FileType::class,[
  126.                 'label' => 'Dateien',
  127.                 'data_class' => null,
  128.                 'required' => false,
  129.                 'multiple' => true,
  130.                 'mapped' => false,
  131.                 'constraints' => [
  132.                     new Assert\All([
  133.                         new File(['maxSize' => '100m'])
  134.                     ])
  135.                 ]
  136.             ])
  137.             ->add('submit'SubmitType::class, [
  138.                 'label' => 'Senden',
  139.                 'attr' => [
  140.                     'class' => 'btn btn-primary',
  141.                 ],
  142.             ])
  143.         ;
  144.     }
  145.     public function configureOptions(OptionsResolver $resolver): void
  146.     {
  147.         $resolver->setDefaults([
  148.             'data_class' => Claim::class,
  149.         ]);
  150.     }
  151. }