src/Form/ClaimTechType.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 ClaimTechType 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.                 'html5' => true,
  52.                 'constraints' => [
  53.                     new Assert\Range([
  54.                         'min' => 0,
  55.                         'max' => 9999999999999.99,
  56.                     ]),
  57.                 ],
  58.             ])
  59.             ->add('damageBy'NameAddressBlockType::class, [
  60.                 'label' => "Wer hat den Schaden verursacht?",
  61.                 'required' => false,
  62.                 'constraints' => [
  63.                     new Assert\NotBlank(),
  64.                 ],
  65.             ])
  66.             ->add('policeReport'null, [
  67.                 'label' => "Polizeirapport aufgenommen von",
  68.                 'required' => false,
  69.             ])
  70.             ->add('items'CollectionType::class, [
  71.                 'label' => false,
  72.                 'entry_type' => ClaimItemType::class,
  73.                 'entry_options' => [
  74.                     'with_owner' => false,
  75.                     'with_damage_amount' => true,
  76.                 ],
  77.                 'allow_add' => true,
  78.                 'allow_delete' => true,
  79.                 'by_reference' => false,
  80.                 'prototype' => true,
  81.                 'prototype_name' => '__item__',
  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. }