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

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