src/Form/UploadSkudType.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Skud;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. use Symfony\Component\Form\Extension\Core\Type\FileType;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. class UploadSkudType extends AbstractType
  10. {
  11. public function buildForm(FormBuilderInterface $builder, array $options): void
  12. {
  13. $builder
  14. ->add('file', FileType::class, [
  15. 'label' => 'Фактические данные СКУД',
  16. // unmapped means that this field is not associated to any entity property
  17. 'mapped' => false,
  18. // make it optional so you don't have to re-upload the PDF file
  19. // every time you edit the Product details
  20. 'required' => true,
  21. // unmapped fields can't define their validation using attributes
  22. // in the associated entity, so you can use the PHP constraint classes
  23. 'constraints' => [
  24. new Assert\File([
  25. 'maxSize' => '1024k',
  26. 'mimeTypes' => [
  27. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  28. 'application/vnd.ms-excel',
  29. ],
  30. 'mimeTypesMessage' => 'Please upload a valid XLS document',
  31. ])
  32. ],
  33. ])
  34. ;
  35. }
  36. public function configureOptions(OptionsResolver $resolver): void
  37. {
  38. $resolver->setDefaults([
  39. 'data_class' => Skud::class,
  40. ]);
  41. }
  42. }