sonataAdminBundle顶部导航用户名和注销按钮

时间:2013-11-25 19:14:41

标签: symfony sonata-admin symfony-2.3

目前 2.3 版本中的Symfony2。我在sonataAdminBundle版本中安装了dev-master。我fosUserBundle也有dev-master。问题是我在管理面板(导航)顶部没有用户名注销按钮。

我注意到user_block.html.twig说:

{% block user_block %}{# Customize this value #}{% endblock %}

但我该如何定制呢?默认捆绑设置没有用于注销的导航?

2 个答案:

答案 0 :(得分:4)

我认为您应该安装SonataUserBundle覆盖user_block.html.twig模板以及您要查找的内容:

{% block user_block %}
    {% if app.user %}
        {{ app.user }}

        {% if is_granted('ROLE_PREVIOUS_ADMIN') and sonata_user.impersonating %}
            <a href="{{ url(sonata_user.impersonating.route, sonata_user.impersonating.parameters| merge({'_switch_user': '_exit'})) }}">(exit)</a>
        {% endif %}

        - <a href="{{ url('sonata_user_admin_security_logout') }}">{{ 'user_block_logout'|trans({}, 'SonataUserBundle') }}</a>
    {% endif %}
{% endblock %}

以下是模板:https://github.com/sonata-project/SonataUserBundle/blob/master/Resources/views/Admin/Core/user_block.html.twig

答案 1 :(得分:3)

您可以使用此代码替换它以获取sonata 3.x版本中的所有内容:

{% block user_block %}
    {% if app.user %}
        {% set _bg_class          = "bg-light-blue" %}
        {% set _logout_uri        = url('sonata_user_admin_security_logout') %}
        {% set _logout_text       = 'user_block_logout'|trans({}, 'SonataUserBundle') %}
        {% set _profile_uri       = sonata_user.userAdmin.isGranted('EDIT', app.user) ? sonata_user.userAdmin.generateUrl('edit', {id: sonata_user.userAdmin.id(app.user)}) : sonata_user.userAdmin.generateUrl('show', {id: sonata_user.userAdmin.id(app.user)}) %}
        {% set _profile_text      = 'user_block_profile'|trans({}, 'SonataUserBundle') %}
        {% set _user_image        = asset(sonata_user.defaultAvatar) %}
        {# Customize this with your profile picture implementation, see below for example #}
        {#{% set _user_image  = app.user.profilePicture|default(asset(sonata_user.defaultAvatar)) %}#}

        {% if is_granted('ROLE_PREVIOUS_ADMIN') and sonata_user.impersonating %}
            {% set _bg_class    = "bg-light-green" %}
            {% set _logout_uri  = url(sonata_user.impersonating.route, sonata_user.impersonating.parameters| merge({'_switch_user': '_exit'})) %}
            {% set _logout_text = 'switch_user_exit'|trans({}, 'SonataUserBundle') %}
        {% endif %}

        <li class="user-header {{ _bg_class }}">
            {% if _user_image %}
                <img src="{{ _user_image }}" class="img-circle" alt="Avatar" />
            {% endif %}
            <p>{{ app.user }}</p>
        </li>

        {#
            Uncomment to add some information
                <li class="user-body">

                </li>
        #}

        <li class="user-footer">
            <div class="pull-left">
                <a href="{{ _profile_uri }}" class="btn btn-default btn-flat"><i class="fa fa-user"></i> {{ _profile_text }}</a>
            </div>

            <div class="pull-right">
                <a href="{{ _logout_uri }}" class="btn btn-default btn-flat"><i class="fa fa-sign-out fa-fw"></i> {{ _logout_text }}</a>
            </div>
        </li>
    {% endif %}
{% endblock %}