<?php
namespace App\Form;
use App\Entity\Parcel;
use App\Entity\Station;
use App\Entity\WayBill;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class WayBillForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('receiverName', TextType::class)
->add('receiverPhoneNumber', TextType::class)
->add('senderName', TextType::class)
->add('senderPhoneNumber', TextType::class)
->add('toStation', EntityType::class, [
'class' => Station::class,
'query_builder' => function(EntityRepository $er){
return $er->createQueryBuilder('i')
->andWhere('i.isActive= true')
->andWhere('i.isMobile = false')
->setMaxResults(50);
},
'placeholder' => 'Please Select Destination',
])
->add('transaction', TransactionForm::class)
->add('parcelValue', IntegerType::class)
->add('parcels', CollectionType::class, [
'entry_type' => ParcelForm::class,
'allow_add' => true,
'prototype' => true,
'entry_options' => [
'label' => false
],
'allow_delete' => true,
'by_reference' => false,
'delete_empty' => function (Parcel $parcel = null) {
return null === $parcel || empty($parcel->getDescription());
},
]);
}
public function configureOptions(OptionsResolver $resolver) {
$resolver
->setDefaults([
'data_class' =>WayBill::class,
'validation_groups' => [
'Default','collection'
]
]);
}
public function getBlockPrefix()
{
return 'app_bundle_way_bill_form';
}
}