I'm trying to access the entity for a given embedded form in the parent CollectionType
inside FormBuilder
:
ParentType
Class ParentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('children', CollectionType::class, array(
'entry_type' => ChildType::class
);
}
}
ChildType
class ChildType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$child = $builder->getData(); // this returns null
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'VendorBundleEntityChild',
);
}
}
While this works in a normal form, $child
is being returned as null. How can I access the Child
entity inside ChildType
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…