|
@@ -1,7 +1,7 @@
|
|
|
KnpMenu
|
|
|
=======
|
|
|
|
|
|
-The admin comes with `KnpMenu <https://github.com/KnpLabs/KnpMenu>`_ integration.
|
|
|
+The admin comes with `KnpMenu`_ integration.
|
|
|
It integrates a menu with the KnpMenu library. This menu can be a SonataAdmin service, a menu created with a Knp menu provider or a route of a custom controller.
|
|
|
|
|
|
Add a custom controller entry in the menu
|
|
@@ -81,7 +81,7 @@ The following configuration uses a menu provider to populate the menu group ``my
|
|
|
provider: 'MyBundle:MyMenuProvider:getMyMenu'
|
|
|
icon: '<i class="fa fa-edit"></i>'
|
|
|
|
|
|
-With KnpMenuBundle you can create a custom menu by using a builder class or by declaring it as a service. Please see the `Knp documentation <http://symfony.com/doc/current/bundles/KnpMenuBundle/index.html#create-your-first-menu>`_ for further information.
|
|
|
+With KnpMenuBundle you can create a custom menu by using a builder class or by declaring it as a service. Please see the `Knp documentation`_ for further information.
|
|
|
|
|
|
In sonata, whatever the implementation you choose, you only have to provide the menu alias to the provider config key:
|
|
|
|
|
@@ -94,3 +94,42 @@ In sonata, whatever the implementation you choose, you only have to provide the
|
|
|
</service>
|
|
|
|
|
|
Please note that when using the provider option, you can't set the menu label via the configuration. It is done in your custom menu.
|
|
|
+
|
|
|
+Extending the menu
|
|
|
+------------------
|
|
|
+
|
|
|
+You can modify the menu via events easily. You can register as many listeners as you want for the event with name ``sonata.admin.event.configure.menu.sidebar``:
|
|
|
+
|
|
|
+.. code-block:: php
|
|
|
+
|
|
|
+ // src/AppBundle/EventListener/MenuBuilderListener.php
|
|
|
+ namespace AppBundle\EventListener;
|
|
|
+
|
|
|
+ use Sonata\AdminBundle\Event\ConfigureMenuEvent;
|
|
|
+
|
|
|
+ class MenuBuilderListener
|
|
|
+ {
|
|
|
+ public function addMenuItems(ConfigureMenuEvent $event)
|
|
|
+ {
|
|
|
+ $menu = $event->getMenu();
|
|
|
+
|
|
|
+ $menu->addChild('reports', array(
|
|
|
+ 'route' => 'app_reports_index',
|
|
|
+ 'labelAttributes' => array('icon' => 'glyphicon glyphicon-stats'),
|
|
|
+ ))->setLabel('Daily and monthly reports');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+.. code-block:: yaml
|
|
|
+
|
|
|
+ services:
|
|
|
+ app.menu_listener:
|
|
|
+ class: AppBundle\EventListener\MenuBuilderListener
|
|
|
+ tags:
|
|
|
+ - { name: kernel.event_listener, event: sonata.admin.event.configure.menu.sidebar, method: addMenuItems }
|
|
|
+
|
|
|
+Please see the `Using events to allow a menu to be extended`_ for further information.
|
|
|
+
|
|
|
+.. _KnpMenu: https://github.com/KnpLabs/KnpMenu
|
|
|
+.. _Knp documentation: http://symfony.com/doc/current/bundles/KnpMenuBundle/index.html#create-your-first-menu
|
|
|
+.. _Using events to allow a menu to be extended: http://symfony.com/doc/master/bundles/KnpMenuBundle/events.html
|