Sonata admin bundle preview image from some entity in list mapper without sonata media bundle

谁说我不能喝 提交于 2019-12-04 11:34:00

You need to create a custom template where you display the image of your user, i will assume that your Entity User as a Picture Entity which has a path method that gives the image URL :

picture.html.twig

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
<div>
    {% if object.picture != null %}
    <img src="{{ object.picture.path }}">
    {% else %}
    <span>No picture</span>
    {% endif %}
</div>
{% endblock %}

You know have to use this template in your list

class UserAdmin extends Admin
{
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id')
            ->add('picture', null, array(
                'template' => 'ApplicationSonataAdminBundle:User:picture.html.twig'
            ));
    }
}

Documentation is available here : http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/list_field_definition.html#custom-template

one separated entity, -no user-, where I have added one media, this for me worked

in admin configureListFields ->add('media', 'string', array('template' => 'SonataMediaBundle:MediaAdmin:list_image.html.twig'))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!