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