Search code examples
symfonysonata-adminsonata

Symfony Sonata admin - disable menu toggle button


Is there a simple sonata configuration to disable the menu toggle button? ('Menu-hamburger' underlined with red in the image below.)

enter image description here

I took a quick look but I can't find anything about it.


Solution

  • Create the following directory in your symfony project, if it doesn't exist yet:

    mkdir -p app/Resources/SonataAdminBundle/views
    

    The option -p will create also the parent directories in the specified path.

    Copy the following file to the newly created directory:

    cp vendor/sonata-project/admin-bundle/Resources/views/standard_layout.html.twig \
    app/Resources/SonataAdminBundle/views/
    

    The command should be written in one line. Because of its length I broke it down to two lines using the backslash \.

    Now you can edit the copied file app/Resources/SonataAdminBundle/views/standard_layout.html.twig.

    Find the following lines (I have them on the lines 115 to 120):

    <a href="#" class="navbar-btn sidebar-toggle" data-toggle="offcanvas" role="button">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
    </a>
    

    Remove them, comment them out, do whatever you need, clear the cache:

    php app/console cache:clear
    

    and refresh the page. Voilà!