假设我与实体Product
有ManyToOne
关系。Category
我们将configureFormFields(FormMapper $form)
执行ProductAdmin
以下操作:
$formMapper->add('category');
Sonata 将渲染一个select
字段。
但我想做的是自定义最终视图select
,因为我想在option
标签中添加一些特定的属性select
(而不是选择本身)。
我之前在 symfony 中通过覆盖类似这样的finishView()
函数来做到这FormType
一点:
public function finishView(FormView $view, FormInterface $form, array $options)
{
$field = 'category';
$choices = $view->children[$field]->vars['choices'];
foreach ($choices as $choice) {
// I can add any attribute to the options like so
$choice->attr['new-attribute'] = 'attribute_value';
}
$view->children[$field]->vars['choices'] = $choices;
}
AbstractAdmin
但是我在奏鸣曲提供的功能中找不到这样的功能!
有没有办法实现这个目标?