src/Form/ClaimHaftType.php line 17

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