0

假设我与实体ProductManyToOne关系。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但是我在奏鸣曲提供的功能中找不到这样的功能!
有没有办法实现这个目标?

4

0 回答 0