src/Form/ClaimSachType.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 ClaimSachType 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('sachOwner'NameAddressBlockType::class, [
  67.                 'label' => "Wer ist der Eigentümer?",
  68.                 'required' => true,
  69.                 'constraints' => [
  70.                     new Assert\NotBlank(),
  71.                 ],
  72.             ])
  73.             ->add('damageBy'NameAddressBlockType::class, [
  74.                 'label' => "Wer hat den Schaden verursacht?",
  75.                 'required' => false,
  76.                 'constraints' => [
  77.                     new Assert\NotBlank(),
  78.                 ],
  79.             ])
  80.             ->add('policeReport'null, [
  81.                 'label' => "Schaden gemeldet bei (Polizei, Feuerwehr, ...)",
  82.                 'required' => true,
  83.             ])
  84.             ->add('policeReportDate'null, [
  85.                 'label' => "Datum der Anzeige",
  86.                 'required' => true,
  87.             ])
  88.             ->add('persons'CollectionType::class, [
  89.                 'label' => false,
  90.                 'entry_type' => PersonType::class,
  91.                 'entry_options' => [],
  92.                 'allow_add' => true,
  93.                 'allow_delete' => true,
  94.                 'by_reference' => false,
  95.                 'prototype' => true,
  96.                 'prototype_name' => '__item__',
  97.             ])
  98.             ->add('remark'null, [
  99.                 'label' => "Beschädigte Sachen / Weitere Angaben / Bemerkungen",
  100.                 'required' => false,
  101.             ])
  102.             ->add('name'null, [
  103.                 'label' => false,
  104.                 'required' => true,
  105.                 'constraints' => [
  106.                     new Assert\NotBlank(),
  107.                 ],
  108.                 'attr' => [
  109.                     'placeholder' => 'Name',
  110.                 ],
  111.             ])
  112.             ->add('email'EmailType::class, [
  113.                 'label' => false,
  114.                 'required' => true,
  115.                 'constraints' => [
  116.                     new Assert\NotBlank(),
  117.                     new Assert\Email(),
  118.                 ],
  119.                 'attr' => [
  120.                     'placeholder' => 'Email',
  121.                 ],
  122.             ])
  123.             ->add('ccEmail'EmailType::class, [
  124.                 'label' => false,
  125.                 'required' => false,
  126.                 'constraints' => [
  127.                     new Assert\Email(),
  128.                 ],
  129.                 'attr' => [
  130.                     'placeholder' => 'CC Email',
  131.                 ],
  132.             ])
  133.             ->add('claimFiles'FileType::class,[
  134.                 'label' => 'Dateien',
  135.                 'data_class' => null,
  136.                 'required' => false,
  137.                 'multiple' => true,
  138.                 'mapped' => false,
  139.                 'constraints' => [
  140.                     new Assert\All([
  141.                         new File(['maxSize' => '100m'])
  142.                     ])
  143.                 ]
  144.             ])
  145.             ->add('submit'SubmitType::class, [
  146.                 'label' => 'Senden',
  147.                 'attr' => [
  148.                     'class' => 'btn btn-primary',
  149.                 ],
  150.             ])
  151.         ;
  152.     }
  153.     public function configureOptions(OptionsResolver $resolver): void
  154.     {
  155.         $resolver->setDefaults([
  156.             'data_class' => Claim::class,
  157.         ]);
  158.     }
  159. }