Customize form field rendering

前端 未结 3 1167
失恋的感觉
失恋的感觉 2020-12-30 09:23

I would like to customize the rendering of a form field in the edit page from sonata admin bundle to include an applet that uses the text content of a field.

I know

3条回答
  •  滥情空心
    2020-12-30 09:50

    user1254498's solution won't work unless the block name prefix matches the name of the form type. At least with the last version of sonata admin bundle (2.2.12). In this case:

    {# src/mycompany/myBundle/Resources/views/Form/myfield_edit.html.twig #}
    {% block myfield_widget %}
        {% spaceless %}
            {{ block('textarea_widget') }}
        {% endspaceless %}
    {% endblock %}
    

    And, regarding getFormTheme(), you shoud return also the parent theme, otherwise you may break the whole style...

    public function getFormTheme()
    {
        return array_merge(
                parent::getFormTheme(), array(
              'mycompanyBundle:Form:myfield_edit.html.twig')
        );        
    }
    

    Also, you can access the admin service in the twig template with the variable sonata_admin.admim.

提交回复
热议问题