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