Menu
Represents a navigation menu in the backend module document header, typically rendered as a dropdown selector that allows users to switch between different views or modes within a module.
Menus consist of multiple MenuItems and are registered with the MenuRegistry in the DocHeaderComponent. The menu is automatically rendered in the module's document header.
Example:
public function __construct(
protected readonly ComponentFactory $componentFactory,
) }
public function myAction(): ResponseInterface
{
$menuRegistry = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry();
$menu = $this->componentFactory->createMenu();
$menu->setIdentifier('myModuleMenu')
->setLabel('Select View');
$menuItem1 = $this->componentFactory->createMenuItem()
->setTitle('List View')
->setHref($listViewUrl)
->setActive(true);
$menu->addMenuItem($menuItem1);
$menuItem2 = $this->componentFactory->createMenuItem()
->setTitle('Grid View')
->setHref($gridViewUrl);
$menu->addMenuItem($menuItem2);
$menuRegistry->addMenu($menu);
}
Table of Contents
Properties
- $identifier : string
- $label : string
- Label of the Menu (displayed as the dropdown label)
- $menuItems : array<string|int, mixed>
Methods
- addMenuItem() : static
- Adds a new menuItem
- getDataIdentifier() : string
- getIdentifier() : string
- getLabel() : string
- getMenuItems() : array<string|int, mixed>
- isValid() : bool
- makeMenuItem() : MenuItem
- setIdentifier() : static
- setLabel() : static
Properties
$identifier
protected
string
$identifier
= ''
$label
Label of the Menu (displayed as the dropdown label)
protected
string
$label
= ''
$menuItems
protected
array<string|int, mixed>
$menuItems
= []
Methods
addMenuItem()
Adds a new menuItem
public
addMenuItem(MenuItem $menuItem) : static
Parameters
- $menuItem : MenuItem
-
The menuItem to add to the menu
Tags
Return values
staticgetDataIdentifier()
public
getDataIdentifier() : string
Return values
stringgetIdentifier()
public
getIdentifier() : string
Return values
stringgetLabel()
public
getLabel() : string
Return values
stringgetMenuItems()
public
getMenuItems() : array<string|int, mixed>
Return values
array<string|int, mixed>isValid()
public
isValid() : bool
Return values
boolmakeMenuItem()
public
makeMenuItem() : MenuItem
since v14, will be removed in v15. Use GeneralUtility::makeInstance(MenuItem::class) directly or inject ComponentFactory and use createMenuItem().
Return values
MenuItemsetIdentifier()
public
setIdentifier(string $identifier) : static
Parameters
- $identifier : string
Return values
staticsetLabel()
public
setLabel(string $label) : static
Parameters
- $label : string
-
LabelText for the menu (accepts LLL syntax)