繁体   English   中英

Sonata Admin 4:添加附加显示以编辑表单

[英]Sonata Admin 4: Add an additional display to edit form

似乎可以简单地将字符串/模板放入列表视图,但在 Sontata Admin 4 中对实体的编辑视图是否也可以这样做?

我发现https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/reference/templates/#configuring-templates ,但它只允许不授予对表单本身的访问权限。 这是我在base_edit.html.twig中找到的包含:

{% block form %}
    {{ block('parentForm') }}
{% endblock %}

我想实现这个你:
在此处输入图像描述

这怎么可能?

好的,看起来输入的help属性可以用标记填充:

src/Admin/PageAdmin.php

class PageAdmin extends AbstractAdmin {

   // ...
   
    protected function configureFormFields(FormMapper $formMapper) : void
    {

        /** @var Page $page */
        $page = $this->getSubject();
        $adminHint = '';
        if ($page) {
            $adminHint = implode(', ',array_map(function (User $admin) {
                return "<strong><a href='/admin/sso/user/{$admin->getId()}/show' target='_blank'>{$admin->getUsername()}</a></strong>";
            }, $page->getExplicitAdmins()->toArray()));
        }

        $formMapper
            ->add('title', TextType::class)
            // ....
            ->add('admins', ModelAutocompleteType::class, [
                'multiple' => true,
                'required' => false,
                'property' => ['username', 'id'],
                'btn_add' => false,
                'help' => $adminHint ? "$adminHint have already explicit edit rights (might be inherited from parents). Admins entered here will also get access to all subpages." : "Admins entered here will also get access to all subpages.", // <-- some dynamic content
                'help_html' => true, // <-- to enable html rendering
            ])
}

另请参阅https://symfony.com/bundles/SonataAdminBundle/3.x/cookbook/recipe_image_previews.html

让我有点烦恼的是,这相当混乱。 在这里渲染一个模板会使它更干净。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM