2

I have installed Sonata-admin-bundle 3.x with User-bundle and FOSUserBundle. Mostly all of this stuff is working great but in admin panel the logout button is missing.The logout button show in the footer in DEV environment but not in PROD. Anyone knows how to add the logout button to upper navigation bar in the top right corner ? Can someone help me ?

 {% 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        = sonata_user.defaultAvatar ? asset(sonata_user.defaultAvatar) : null %}
        {# 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>{
        <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 %}
Mawcel
  • 1,967
  • 15
  • 22
Gothic
  • 43
  • 5
  • In your page, the logout uri is defined as `...`. The real url is `url('sonata_user_admin_security_logout')`. Just copy/paste where you need it to be ? – mickdev Mar 15 '17 at 10:28
  • ok thanks for help :) but not that was key to me problem. I jut must customize user_block but in core-bundle. – Gothic Mar 16 '17 at 23:25

3 Answers3

2

To see the logout button you need to assign the role

ROLE_SONATA_ADMIN

to the user.

Sebastian Viereck
  • 5,455
  • 53
  • 53
1

Make sure that you have the role ROLE_ADMIN assigned to your user, e.g. within his role hierarchy in your security.yml.

I had the exact same problem, and this solved it.

Dorrian
  • 113
  • 1
  • 7
0

At first, you have to check or set sonata admin role in configuration (Sonata Admin Bundle Configuration Reference):

sonata_admin:
    security:
        role_admin: ROLE_SUPER_DUPER_ADMIN

By default it is ROLE_SONATA_ADMIN.

Then don't forget to update role hierarchy in security.yaml and set the corresponding role to the user.