How to reproduce this:
1. Create a collection of some type
<?php
$builder->add('foo', 'collection', array(
'type' => new BarType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => 'this_is_prototype',
'options' => array(
'data_class' => 'Acme\FooBundle\Entity\Bar'
),
));
2. Create BarType
<?php
class BarType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
var_dump(array(
$builder->getForm()->getName() => $builder->hasParent()
));
$builder->add('bar', 'text');
// this actually is not relevant, just adding anything
// so that bar form is not empty
}
}
Result of var_dump()
If our collection holds 3 Bar objects then the result will be:
array (size=1)
'this_is_prototype' => boolean true
array (size=1)
0 => boolean false
array (size=1)
1 => boolean false
array (size=1)
2 => boolean false
Conclusion
In buildForm $builder->getParent() will return parent builder only for prototype.
Issue / question
I need to access parent form to get some parameters. Why is parent dropped for existing collection elements? Is there any workaround?
bschussek: