Skip to content

Back Office menus

Back Office menus are based on the KnpMenuBundle and are easily extensible.

Tip

For general information on how to use MenuBuilder, see the official KnpMenuBundle documentation.

Menus are extensible using event subscribers, for example:

 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
27
28
29
30
31
32
33
34
35
36
37
<?php declare(strict_types=1);

namespace App\EventSubscriber;

use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use EzSystems\EzPlatformAdminUi\Menu\MainMenuBuilder;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MyMenuSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            ConfigureMenuEvent::MAIN_MENU => ['onMainMenuConfigure', 0],
        ];
    }

    public function onMainMenuConfigure(ConfigureMenuEvent $event)
    {
        $menu = $event->getMenu();

        $menu[MainMenuBuilder::ITEM_CONTENT]->addChild(
            'all_content_list',
            [
                'label' => 'Content List',
                'route' => 'all_content_list.list',
                'attributes' => [
                    'class' => 'custom-menu-item',
                ],
                'linkAttributes' => [
                    'class' => 'custom-menu-item-link',
                ],
            ]
        );
    }

}

Tip

The event subscriber is registered as a service by default, if autoconfigure is enabled. If not, register it as a service and tag with kernel.event.subscriber.

You can listen to the following events:

Main menu ConfigureMenuEvent::MAIN_MENU
ConfigureMenuEvent::USER_MENU
Content view ConfigureMenuEvent::CONTENT_SIDEBAR_RIGHT
ConfigureMenuEvent::CONTENT_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::CONTENT_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::CONTENT_SIDEBAR_LEFT
Trash ConfigureMenuEvent::TRASH_SIDEBAR_RIGHT
Section ConfigureMenuEvent::SECTION_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::SECTION_CREATE_SIDEBAR_RIGHT
Policies and permissions ConfigureMenuEvent::POLICY_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::POLICY_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::ROLE_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::ROLE_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::ROLE_COPY_SIDEBAR_RIGHT
ConfigureMenuEvent::USER_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::USER_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::ROLE_ASSIGNMENT_CREATE_SIDEBAR_RIGHT
Languages ConfigureMenuEvent::LANGUAGE_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::LANGUAGE_EDIT_SIDEBAR_RIGHT
Object states ConfigureMenuEvent::OBJECT_STATE_GROUP_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::OBJECT_STATE_GROUP_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::OBJECT_STATE_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::OBJECT_STATE_EDIT_SIDEBAR_RIGHT
Content Types ConfigureMenuEvent::CONTENT_TYPE_GROUP_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::CONTENT_TYPE_GROUP_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::CONTENT_TYPE_CREATE_SIDEBAR_RIGHT
ConfigureMenuEvent::CONTENT_TYPE_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::CONTENT_TYPE_SIDEBAR_RIGHT
URLs and wildcards ConfigureMenuEvent::URL_EDIT_SIDEBAR_RIGHT
ConfigureMenuEvent::URL_WILDCARD_EDIT_SIDEBAR_RIGHT
User settings ConfigureMenuEvent::USER_PASSWORD_CHANGE_SIDEBAR_RIGHT
ConfigureMenuEvent::USER_SETTING_UPDATE_SIDEBAR_RIGHT

Adding menu items

To add a menu item, use the addChild() method. Provide the method with the new menu item's identifier and, optionally, with parameters.

The following method adds a new menu item under Content with custom attributes:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
        $menu[MainMenuBuilder::ITEM_CONTENT]->addChild(
            'all_content_list',
            [
                'label' => 'Content List',
                'route' => 'all_content_list.list',
                'attributes' => [
                    'class' => 'custom-menu-item',
                ],
                'linkAttributes' => [
                    'class' => 'custom-menu-item-link',
                ],
            ]
        );

label is used for the new menu item in the interface. route is the name of the route that the menu item leads to.

attributes adds attributes (such as CSS classes) to the container <li> element of the new menu item. linkAttributes adds attributes to the <a> element.

Passing a parameter to a menu item

You can also pass parameters to templates used to render menu items with template_parameters:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$menu->addChild(
    'all_content_list',
    [
        'extras' => [
            'template' => 'list/all_content_list.html.twig',
            'template_parameters' => [
                'custom_parameter' => 'value',
            ],
        ],
    ]
);

You can then use the variable custom_parameter in templates/list/all_content_list.html.twig.

Translatable labels

To have translatable labels, use translation.key from the messages domain:

1
2
3
4
5
6
7
8
9
$menu->addChild(
    'all_content_list',
    [
        'label' => 'translation.key',
        'extras' => [
            'translation_domain' => 'messages',
        ],
    ]
);

Modifying menu items

To modify the parameters of an existing menu item, use the setExtra() method.

Custom icons

You can use the extras.icon parameter to define an icon for a menu item. For example, the following code changes the default icon for the "Create" button in content view:

1
2
        $menu->getChild('content__sidebar_right__create')
             ->setExtra('icon_path', '/bundles/ibexaplatformicons/img/all-icons.svg#notice');

Removing menu items

To remove a menu item, for example, to remove the Copy subtree item from the right menu in content view, use the following event listener:

1
        $menu->removeChild('content__sidebar_right__copy_subtree');