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