src/Form/api/ApiWayBillForm.php line 32

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('toStation'EntityType::class, [
  28.                 'class' => Station::class,
  29.                 'query_builder' => function(EntityRepository $er){
  30.                     return $er->createQueryBuilder('i')->setMaxResults(50);
  31.                 },
  32.                 'placeholder' => 'Please Select Destination',
  33.             ])
  34.             ->add('transaction'TransactionForm::class)
  35.             ->add('parcels'CollectionType::class, [
  36.                 'entry_type' => ParcelForm::class,
  37.                 'allow_add' => true,
  38.                 'prototype' => true,
  39.                 'entry_options' => [
  40.                     'label' => false
  41.                 ],
  42.                 'allow_delete' => true,
  43.                 'by_reference' => false,
  44.                 'delete_empty' => function (Parcel $parcel null) {
  45.                     return null === $parcel || empty($parcel->getDescription());
  46.                 },
  47.             ]);
  48.     }
  49.     public function configureOptions(OptionsResolver $resolver) {
  50.         $resolver
  51.             ->setDefaults([
  52.                 'data_class' =>WayBill::class,
  53.                 'validation_groups' => [
  54.                     'Default','collection'
  55.                 ]
  56.             ]);
  57.     }
  58.     public function getBlockPrefix()
  59.     {
  60.         return 'app_bundle_api_way_bill_form';
  61.     }
  62. }