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