简体   繁体   English

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

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

It appears to be possible to simply put a string / template to the list view, but is the same possible to the edit view of an entity in Sontata Admin 4?似乎可以简单地将字符串/模板放入列表视图,但在 Sontata Admin 4 中对实体的编辑视图是否也可以这样做?

I found https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/reference/templates/#configuring-templates , but it only allows does not give access to the form itself.我发现https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/reference/templates/#configuring-templates ,但它只允许不授予对表单本身的访问权限。 This is the include I found in base_edit.html.twig :这是我在base_edit.html.twig中找到的包含:

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

I would like to achieve this thou:我想实现这个你:
在此处输入图像描述

How would this be possible?这怎么可能?

Ok, it looks like the help attribute of an input can be filled with markup:好的,看起来输入的help属性可以用标记填充:

src/Admin/PageAdmin.php : 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
            ])
}

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

What bugs me a bit is, that this is rather messy.让我有点烦恼的是,这相当混乱。 Rendering a template here would make it much cleaner.在这里渲染一个模板会使它更干净。

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

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