(Symfony 4)从多选实体表单字段创建选择下拉列表

时间:2019-01-14 05:26:39

标签: forms symfony select

我有一个Symfony表单类型类,如下所示:

class FeedFilterType extends AbstractType

{
 /**
 * @var UserProvider
 */
protected $userProvider;

/**
 * @var UserRepository $userRepository
 */
protected $userRepository;

public function __construct(UserProvider $userProvider, UserRepository $userRepository)
{
    $this->userProvider = $userProvider;
    $this->userRepository = $userRepository;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('creators', EntityType::class, [
            'class' => User::class,
            'choices'  => $this->userRepository->getCreatorsSubscribedToByUser($this->userProvider->getCurrentUser()),
            'choice_label' => 'name',
            'required' => false,
            'multiple' => true,
            'expanded' => true
        ])
    ;
}

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array());
}

}

它可以正常工作,因为它可以带回用户数组,但是当我将其添加到树枝时,例如:

{{ form_widget(feedFilterForm.creators) }}

它是这样的:

enter image description here

我可以从结果实体数组中手动​​构建一个选择下拉列表,但是Symfony是否有一个内置的select DOM html类型,它是从表单返回的实体数组产生的?

0 个答案:

没有答案