MenuItem extends AbstractControl

Represents a single item within a Menu in the backend module document header.

Each MenuItem has a title, URL (href), and can be marked as active to indicate the current selection.

MenuItems inherit from AbstractControl, providing access to common properties like title, CSS classes, and data attributes.

Example:

public function __construct(
    protected readonly ComponentFactory $componentFactory,
) }

public function myAction(): ResponseInterface
{
    $menu = $this->componentFactory->createMenu();
    $menuItem = $this->componentFactory->createMenuItem()
        ->setTitle('List View')
        ->setHref('/my-module?view=list')
        ->setActive(true)  // Marks this item as currently selected
        ->setClasses('my-custom-class')
        ->setDataAttributes(['action' => 'switch-view']);
    $menu->addMenuItem($menuItem);
}

Table of Contents

Properties

$active  : bool
$classes  : string
CSS classes to apply to the rendered element
$dataAttributes  : array<string, string>
HTML data-* attributes for the control
$href  : string
$title  : string
Title/label text for the control

Methods

getClasses()  : string
getDataAttributes()  : array<string|int, mixed>
getHref()  : string
getTitle()  : string
isActive()  : bool
isValid()  : bool
setActive()  : static
setClasses()  : static
setDataAttributes()  : static
setHref()  : static
setTitle()  : static

Properties

$classes

CSS classes to apply to the rendered element

protected string $classes = ''

$dataAttributes

HTML data-* attributes for the control

protected array<string, string> $dataAttributes = []

Key-value pairs (e.g., ['action' => 'save'])

$title

Title/label text for the control

protected string $title = ''

Methods

getClasses()

public getClasses() : string
Return values
string

getDataAttributes()

public getDataAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHref()

public getHref() : string
Return values
string

getTitle()

public getTitle() : string
Return values
string

isActive()

public isActive() : bool
Return values
bool

isValid()

public isValid() : bool
Return values
bool

setActive()

public setActive(bool $active) : static
Parameters
$active : bool
Return values
static

setClasses()

public setClasses(string $classes) : static
Parameters
$classes : string
Return values
static

setDataAttributes()

public setDataAttributes(array<string|int, mixed> $dataAttributes) : static
Parameters
$dataAttributes : array<string|int, mixed>
Return values
static

setHref()

public setHref(string $href) : static
Parameters
$href : string
Return values
static

setTitle()

public setTitle(string $title) : static
Parameters
$title : string
Return values
static

        
On this page

Search results