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 |
|
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
.
Menu events¶
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|