Menu

class \TYPO3\CMS\Backend\Template\Components\Menu\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

Methods

addMenuItem()  : static
Adds a new menuItem
getDataIdentifier()  : string
getIdentifier()  : string
getLabel()  : string
getMenuItems()  : array
isValid()  : bool
setIdentifier()  : static
setLabel()  : static

Properties

$identifier

protected string $identifier = ''

$label

Label of the Menu (displayed as the dropdown label)

protected string $label = ''

Methods

addMenuItem()

Adds a new menuItem

public addMenuItem(MenuItem $menuItem) : static

Parameters

$menuItem : MenuItem

The menuItem to add to the menu

Tags

throws
InvalidArgumentException

In case a menuItem is not valid

Return values

static

getDataIdentifier()

public getDataIdentifier() : string

Return values

string

getIdentifier()

public getIdentifier() : string

Return values

string

getLabel()

public getLabel() : string

Return values

string

getMenuItems()

public getMenuItems() : array

Return values

array

isValid()

public isValid() : bool

Return values

bool

setIdentifier()

public setIdentifier(string $identifier) : static

Parameters

$identifier : string

Return values

static

setLabel()

public setLabel(string $label) : static

Parameters

$label : string

LabelText for the menu (accepts LLL syntax)

Return values

static
On this page