如果你坚持使用CollectionType(我在你的截图中没有看到理由),那么你可以这样做:
$builder->add('entity1', CollectionType::class, [
'label' => 'entity.recipe.entity1',
'entry_type' => \AppBundle\Form\Type\Entity1Type::class,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'prototype_name' => '__EntityId__',
'entry_options' => ['required' => false],
]);
$builder->add('entity2', CollectionType::class, [
'label' => 'entity.recipe.entity2',
'entry_type' => \AppBundle\Form\Type\Entity2Type::class,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'prototype_name' => '__EntityId__',
'entry_options' => ['required' => false],
]);
...
添加任意数量的实体类型,每个类型都将是一个包含零个或多个项目的集合。