I have form collection which need to handle more than 500 entity instances. After I increased timeout to 60s and increased max_input_vars form work but it is annoying how slow it is. Rendering form is slow but submitting that big form is pain in the ass.
I was considering creating plain HTML form but there is some other drawback suck as validation. So, is there any proper way to handle that big set of data via symfony form ?
CONTROLLER:
public function ratesCardAction() {
$bannerList = $this->data;
$em = $this->getDoctrine()->getManager();
$form = $this->createForm(new AdvertiserRatesType($bannerList));
if ('POST' == $this->getRequest()->getMethod()) {
$form->handleRequest($this->getRequest());
$advertiserCampaign = $form->getData();
if ($form->isValid()) {
foreach ($advertiserCampaign['campaignsAdZones'] as $campaignAdZone) {
$em->persist($campaignAdZone);
}
$em->flush();
}
}
return array(
'form' => $form->createView()
);
}
class AdvertiserRatesType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder ->add('campaignsAdZones', 'collection', array(
'type' => new AdvertiserRatePerCountryType(),
'data' => $this->rates,
'empty_data' => null,
'options' => array(
'attr' => array('class' => 'campaignAdZoneItem')
)
))
;
}
}
...
and embedded form looks like:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('class', 'entity', array(
'class' => 'AcmeCmsBundle:PublisherTypes',
'property' => 'class',
'read_only' => true,
'disabled' => true
)
)
->add('country', 'entity', array(
'class' => 'AcmeCmsBundle:Countries',
'property' => 'name',
)
)
->add('text1')
->add('text2')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\CmsBundle\Entity\Rates'
));
}