我使用formType(TagsType)在一个包中创建了一个标签系统,我将其包含在我的主formType中(见下文)。 我想知道如何将$ options参数值从MyFormType发送到TagsType。
//...
use EC\TagBundle\Form\Type\TagsType;
class MyFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
//...
->add('tags', TagsType::class)
//...
;
}
}
我的TagsType
//...
use Symfony\Component\Form\Extension\Core\Type\TextType;
class TagsType extends AbstractType
{
/**
* @var ObjectManager
*/
private $manager;
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->addModelTransformer( new CollectionToArrayTransformer(), true )
->addModelTransformer( new TagsTransformer($this->manager), true )
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('attr', [
'class' => 'tag-input',
]);
$resolver->setDefault('required', false);
}
public function getParent()
{
// Il retourne un TextType par défaut.
return TextType::class;
}
}
答案 0 :(得分:1)
->add('tags', TagsType::class, ['empty_data' => $options])
TagsType.php
$options = $options['empty_data'];