![](/img/trans.png)
[英]Sonata Admin - how to add Translation to one field and getID of the object?
[英]Sonata Admin - How to add a link to a field
我在 Sonata Admin 的表单上有一个字段:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('filePath', TextType::class, [
'disabled' => true,
]);
}
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('filePath');
}
这与存储文件路径的实体有关。
class User
{
/**
* @ORM\Column(type="string", nullable=true)
*/
private $filePath;
如何更新表单以便我能够单击该字段以便它在另一个选项卡中打开文件?
您需要在configureShowFields
为filePath
字段声明一个模板,这是您的案例的示例:
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('filePath', null, [
'template' => '@App/Admin/file_path_link.html.twig',
]);
}
还有@App/Admin/file_path_link.html.twig
:
{% if value %}
<a href="{{ value }}">click to download</a>
{% else %}
No file path
{% endif %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.