Extending 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/listeners. You can hook into the following events:
ConfigureMenuEvent::MAIN_MENUConfigureMenuEvent::USER_MENUConfigureMenuEvent::CONTENT_SIDEBAR_RIGHTConfigureMenuEvent::CONTENT_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::CONTENT_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::CONTENT_SIDEBAR_LEFTConfigureMenuEvent::TRASH_SIDEBAR_RIGHTConfigureMenuEvent::SECTION_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::SECTION_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::POLICY_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::POLICY_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::ROLE_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::ROLE_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::USER_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::USER_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::ROLE_ASSIGNMENT_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::LANGUAGE_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::LANGUAGE_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::CONTENT_TYPE_GROUP_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::CONTENT_TYPE_GROUP_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::CONTENT_TYPE_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::CONTENT_TYPE_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::URL_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::USER_PASSWORD_CHANGE_SIDEBAR_RIGHTConfigureMenuEvent::OBJECT_STATE_GROUP_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::OBJECT_STATE_GROUP_EDIT_SIDEBAR_RIGHTConfigureMenuEvent::OBJECT_STATE_CREATE_SIDEBAR_RIGHTConfigureMenuEvent::OBJECT_STATE_EDIT_SIDEBAR_RIGHT
An event subscriber can be implemented as follows:
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  |  | 
After creating a subscriber, add it to app/config/services.yml:
1 2 3 4  |  | 
Providing the kernel.event.subscriber tag is necessary only if the autoconfigure option is disabled.
Adding menu items¶
Add a new menu item under "Content" with custom attributes¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  |  | 
Add a top-level menu item with a child¶
1 2 3 4 5 6 7 8  |  | 
Add an item depending on a condition¶
1 2 3 4 5 6 7  |  | 
Add a top-level menu item with URL redirection¶
1 2 3 4 5 6 7 8  |  | 
Modifying menu items¶
Remove the Media menu item from the Content tab¶
1 2 3  |  | 
Reorder menu items, i.e. reverse the order¶
1 2 3  |  | 
Other menu operations¶
Pass a parameter to a menu item¶
You can pass parameters to menu items with template_parameters:
1 2 3 4 5 6 7 8 9 10 11  |  | 
You can then use the variable custom_parameter in AppBundle::menu_item_template.html.twig.
Translatable labels¶
To have translatable labels, use translation.key from the messages domain:
1 2 3 4 5 6 7 8 9 10 11  |  | 
Custom icons¶
You can use the extras.icon parameter to select an icon from the built-in set.
To use your custom icon, use the extras.icon_path parameter:
1 2 3 4 5 6 7 8 9  |  | 
The extras.icon_class parameter adds a custom CSS class to the <svg> element.