Gothic
Gothic

Reputation: 43

Sonata admin-bundle - haven't logout nav bar

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 %}

Upvotes: 2

Views: 1760

Answers (3)

Denys Horobchenko
Denys Horobchenko

Reputation: 539

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.

Upvotes: 0

Sebastian Viereck
Sebastian Viereck

Reputation: 5925

To see the logout button you need to assign the role

ROLE_SONATA_ADMIN

to the user.

Upvotes: 2

Dorrian
Dorrian

Reputation: 113

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.

Upvotes: 1

Related Questions