Documentation

6.4 Add menu items to the Integrated backend

Integrated navigation menu's are managed by the IntegratedMenuBundle, here you can add (or edit) menu items from other bundles.

The IntegratedMenuBundle fires a ConfigureMenuEvent. You can listen to this event by using a Listener or Subscriber. You can read more about events in the Symfony Cookbook.

With this Listener you can edit the menu by adding, removing or replacing menu items:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
// src/AppBundle/EventListener/ConfigureMenuListener.php
 
namespace AppBundle\EventListener;
 
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
 
use Integrated\Bundle\MenuBundle\Event\ConfigureMenuEvent;
 
class ConfigureMenuListener
{
    public function onMenuConfigure(ConfigureMenuEvent $event)
    {
        $menu = $event->getMenu();
 
        // You can check if you want to edit this menu
        if ($menu->getName() !== 'integrated_menu') {
            return;
        }
 
        // Customize the menu
        $label = $menu->addChild('This is just a label');
        $label->addChild('Menu item', array('route' => 'my_route'));
    }
}

After creating the Listener you can register it as a service and notify Symfony that it is a "listener" on the integrated_menu.configure event by using a special "tag":

1
2
3
4
5
6
# app/config/services.yml
services:
    kernel.listener.your_listener_name:
        class: AppBundle\EventListener\ConfigureMenuListener
        tags:
            - { name: kernel.event_listener, event: integrated_menu.configure, method: onMenuConfigure }

Available menu's

The following menu's are available:

integrated_menu          Integrated backend main menu.