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.             ])
  31.             ->add('claimAddress'AddressBlockType::class, [
  32.                 'label' => "Schadenort",
  33.                 'required' => true,
  34.                 'constraints' => [
  35.                     new Assert\NotBlank(),
  36.                 ],
  37.             ])
  38.             ->add('claimDescription'null, [
  39.                 'label' => "Schadenshergang",
  40.                 'required' => true,
  41.                 'constraints' => [
  42.                     new Assert\NotBlank(),
  43.                 ],
  44.             ])
  45.             ->add('damageCosts'NumberType::class, [
  46.                 'scale' => 2,
  47.                 'label' => "Schadensumme",
  48.                 'required' => false,
  49.                 'constraints' => [
  50.                     new Assert\Range([
  51.                         'min' => 0,
  52.                         'max' => 9999999999999.99,
  53.                     ]),
  54.                 ],
  55.             ])
  56.             ->add('damageBy'NameAddressBlockType::class, [
  57.                 'label' => "Wer hat das Ereignis herbeigeführt?",
  58.                 'required' => true,
  59.                 'constraints' => [
  60.                     new Assert\NotBlank(),
  61.                 ],
  62.             ])
  63.             ->add('policeReport'null, [
  64.                 'label' => "Polizeirapport aufgenommen von",
  65.                 'required' => true,
  66.             ])
  67.             ->add('injuredPerson'NameAddressBlockType::class, [
  68.                 'label' => "Geschädigte, verletzte oder getötete Personen",
  69.                 'required' => false,
  70.             ])
  71.             ->add('damagedItem'DamagedItemType::class, [
  72.                 'label' => "Beschädigung, Zerstörung oder Verlust fremder Sachen (Sachbeschädigung)",
  73.                 'required' => true,
  74.             ])
  75.             ->add('persons'CollectionType::class, [
  76.                 'label' => false,
  77.                 'entry_type' => PersonType::class,
  78.                 'entry_options' => [],
  79.                 'allow_add' => true,
  80.                 'allow_delete' => true,
  81.                 'by_reference' => false,
  82.                 'prototype' => true,
  83.                 'prototype_name' => '__item__',
  84.             ])
  85.             ->add('remark'null, [
  86.                 'label' => "Beschädigte Sachen / Weitere Angaben / Bemerkungen",
  87.                 'required' => false,
  88.             ])
  89.             ->add('name'null, [
  90.                 'label' => false,
  91.                 'required' => true,
  92.                 'constraints' => [
  93.                     new Assert\NotBlank(),
  94.                 ],
  95.                 'attr' => [
  96.                     'placeholder' => 'Name',
  97.                 ],
  98.             ])
  99.             ->add('email'EmailType::class, [
  100.                 'label' => false,
  101.                 'required' => true,
  102.                 'constraints' => [
  103.                     new Assert\NotBlank(),
  104.                     new Assert\Email(),
  105.                 ],
  106.                 'attr' => [
  107.                     'placeholder' => 'Email',
  108.                 ],
  109.             ])
  110.             ->add('ccEmail'EmailType::class, [
  111.                 'label' => false,
  112.                 'required' => false,
  113.                 'constraints' => [
  114.                     new Assert\Email(),
  115.                 ],
  116.                 'attr' => [
  117.                     'placeholder' => 'CC Email',
  118.                 ],
  119.             ])
  120.             ->add('claimFiles'FileType::class,[
  121.                 'label' => 'Dateien',
  122.                 'data_class' => null,
  123.                 'required' => false,
  124.                 'multiple' => true,
  125.                 'mapped' => false,
  126.                 'constraints' => [
  127.                     new Assert\All([
  128.                         new File(['maxSize' => '100m'])
  129.                     ])
  130.                 ]
  131.             ])
  132.             ->add('submit'SubmitType::class, [
  133.                 'label' => 'Senden',
  134.                 'attr' => [
  135.                     'class' => 'btn btn-primary',
  136.                 ],
  137.             ])
  138.         ;
  139.     }
  140.     public function configureOptions(OptionsResolver $resolver): void
  141.     {
  142.         $resolver->setDefaults([
  143.             'data_class' => Claim::class,
  144.         ]);
  145.     }
  146. }