src/Form/api/ApiWayBillForm.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form\api;
  3. use App\Entity\Parcel;
  4. use App\Entity\Station;
  5. use App\Entity\WayBill;
  6. use App\Form\ParcelForm;
  7. use App\Form\TransactionForm;
  8. use Doctrine\ORM\EntityRepository;
  9. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  10. use Symfony\Component\Form\AbstractType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  13. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. class ApiWayBillForm extends AbstractType
  18. {
  19. public function buildForm(FormBuilderInterface $builder, array $options) {
  20. $builder
  21. ->add('receiverName', TextType::class)
  22. ->add('receiverPhoneNumber', TextType::class)
  23. ->add('senderName', TextType::class)
  24. ->add('senderPhoneNumber', TextType::class)
  25. ->add('longitude')
  26. ->add('latitude')
  27. ->add('parcelValue')
  28. ->add('toStation', EntityType::class, [
  29. 'class' => Station::class,
  30. 'query_builder' => function(EntityRepository $er){
  31. return $er->createQueryBuilder('i')->setMaxResults(50);
  32. },
  33. 'placeholder' => 'Please Select Destination',
  34. ])
  35. ->add('transaction', TransactionForm::class)
  36. ->add('parcels', CollectionType::class, [
  37. 'entry_type' => ParcelForm::class,
  38. 'allow_add' => true,
  39. 'prototype' => true,
  40. 'entry_options' => [
  41. 'label' => false
  42. ],
  43. 'allow_delete' => true,
  44. 'by_reference' => false,
  45. 'delete_empty' => function (Parcel $parcel = null) {
  46. return null === $parcel || empty($parcel->getDescription());
  47. },
  48. ]);
  49. }
  50. public function configureOptions(OptionsResolver $resolver) {
  51. $resolver
  52. ->setDefaults([
  53. 'data_class' =>WayBill::class,
  54. 'validation_groups' => [
  55. 'Default','collection'
  56. ]
  57. ]);
  58. }
  59. public function getBlockPrefix()
  60. {
  61. return 'app_bundle_api_way_bill_form';
  62. }
  63. }