Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom Sonata page route to the navbar

I've created a custom Sonata page

Simple route

medapp_adminStreamCommands:
    path:     /admin/stream
    defaults: { _controller: MedAppBundle:VideoChat/VideoChat:adminStreamCommands }

Controller that returns the admin pool

  public function adminStreamCommandsAction(Request $request)
    {

        return $this->render('@MedApp/AdminSonata/Stream/stream_commands.html.twig', array(
            'admin_pool' => $this->get('sonata.admin.pool')));
    }

Plain view template

{% extends '@MedApp/AdminSonata/standard_layout.html.twig' %}

{% block content %}
foobar
{% endblock content 

This works, I can access it on my website with /admin/foo and I get a page which has the Sonata admin template with my 'foobar' content.

My question is, how can I add this route to the left and top navbar without having to modify the default template? That is because the left menu is rendered by a KNP menu:

{% block side_bar_nav %}
    {% if app.user and is_granted('ROLE_SONATA_ADMIN') %}
        {{ knp_menu_render('sonata_admin_sidebar', {template: admin_pool.getTemplate('knp_menu_template')}) }}
    {% endif %}
{% endblock side_bar_nav %}

And I somehow need to add my new page to be rendered by this menu.

Normally, a page is added through a service, but these are built on top of an entity:

servicename:
     class: Bundle\Class
     arguments: [~, Bundle\Entity\Entityname, ~]
     tags:
         - { name: sonata.admin, manager_type: orm, group: admin, label: CustomName}

My page is not using an entity, though, just static content or content that is not dependant on an entity.

I know already that I can modify the blocks that generate the menus, but I was thinking that the best way would be to add my class as a service tagged as sonata.admin that doesn't have an orm manager_type, in other words, is not an Entity. How can that be done?

like image 577
George Irimiciuc Avatar asked Nov 17 '15 12:11

George Irimiciuc


2 Answers

You should override standard_layout and modify content of side_bar_nav block. This is simple and fast way. Or you can dig into sonata code to find how to inject something into admin_pool.dashboardgroups - have fun :)

like image 200
Karol Wojciechowski Avatar answered Sep 30 '22 01:09

Karol Wojciechowski


I don't think that's possible, you have to create a new layout, copy the sonata admin layout and customize it to your need.

You can change the layout used by changing the yml configuration for sonata_admin (templates -> layout) or extending the SonataAdmin bundle and creating your own layout.html.twig.

like image 25
HypeR Avatar answered Sep 30 '22 00:09

HypeR