我有SuperType
实体表格Super
。
在这个表单中,我有一个实体collection
的表单类型字段ChildType
Child
class SuperType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('childrens', 'collection', array(
'type' => new ChildType(null, array('my_custom_option' => true)),
}
class ChildType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['my_custom_option']) {
$builder->add('my_custom_field', 'textarea'));
}
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
...
'my_custom_option' => false
));
}
如何my_custom_option
仅更改此SuperType
表单的值?
当然,我尝试通过构造函数传递此选项的方法不起作用。