Added a workaround for an symfony issue with collectiontype.

This commit is contained in:
Jan Böhmer 2020-05-31 19:42:44 +02:00
parent 3021d0d67a
commit 54fa445f06
4 changed files with 36 additions and 3 deletions

View file

@ -53,7 +53,7 @@ class CollectionTypeExtension extends AbstractTypeExtension
public static function getExtendedTypes(): iterable
{
return [CollectionType::class];
return [CollectionType::class, WorkaroundCollectionType::class];
}
public function configureOptions(OptionsResolver $resolver): void

View file

@ -47,6 +47,7 @@ use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use App\Form\Type\StructuralEntityType;
use App\Form\WorkaroundCollectionType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
@ -109,7 +110,7 @@ class OrderdetailType extends AbstractType
}
//Attachment section
$event->getForm()->add('pricedetails', CollectionType::class, [
$event->getForm()->add('pricedetails', WorkaroundCollectionType::class, [
'entry_type' => PricedetailType::class,
'allow_add' => $this->security->isGranted('@parts_prices.create'),
'allow_delete' => $this->security->isGranted('@parts_prices.delete'),

View file

@ -56,6 +56,7 @@ use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\SIUnitType;
use App\Form\Type\StructuralEntityType;
use App\Form\WorkaroundCollectionType;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -258,7 +259,7 @@ class PartBaseType extends AbstractType
]);
//Orderdetails section
$builder->add('orderdetails', CollectionType::class, [
$builder->add('orderdetails', WorkaroundCollectionType::class, [
'entry_type' => OrderdetailType::class,
'allow_add' => $this->security->isGranted('orderdetails.create', $part),
'allow_delete' => $this->security->isGranted('orderdetails.delete', $part),

View file

@ -0,0 +1,31 @@
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
/**
* This a workaround for the issue #37024.
* @package App\Form
*/
class WorkaroundCollectionType extends CollectionType
{
/**
* Use the original implementation for finishView() instead of the one, the one that cause the bug.
* @param FormView $view
* @param FormInterface $form
* @param array $options
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
if ($view->vars['prototype']->vars['multipart']) {
$view->vars['multipart'] = true;
}
}
}