I'm struggling with symfony3 forms and the CollectionType class:
I have a page with several complex forms. I do not use any database (the validated forms are sent to a foreign REST-service)
Now let's say I have an entity object for my request called "ProductService":
class ProductService
{
/** @var string */
private $msg;
/** @var array*/
private $products
}
And a class ProductServiceType to render the form:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('products', CollectionType::class, [
'entry_type' => ProductType::class,
])
->add('msg' [...]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ProductService::class,
]);
}
With this setup, everything works like a charm, all products will be added in the products array of my entity. The problem is, i want $products to be a SplObjectStorage-object:
class ProductService
{
/** @var string */
private $msg;
/** @var SplObjectStorage */
private $products
}
If i set it to this and attach an empty object into it, symfony can't render the form any more. It throws following error: Warning: SplObjectStorage::offsetExists() expects parameter 1 to be object, string given
So, can anybody tell me, how to handle the collectionType in an entity when NOT using doctrine and orm? Is the only possibility using arrays, or is there any documentation for this case, i did not find? (I'm still wondering how symfony calls offsetExists, there must be someting implemented to handle SplObjectStorage, or am i wrong?)