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
$active
protected
bool
$active
= false
$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'])
$href
protected
string
$href
= ''
$title
Title/label text for the control
protected
string
$title
= ''
Methods
getClasses()
public
getClasses() : string
Return values
stringgetDataAttributes()
public
getDataAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getHref()
public
getHref() : string
Return values
stringgetTitle()
public
getTitle() : string
Return values
stringisActive()
public
isActive() : bool
Return values
boolisValid()
public
isValid() : bool
Return values
boolsetActive()
public
setActive(bool $active) : static
Parameters
- $active : bool
Return values
staticsetClasses()
public
setClasses(string $classes) : static
Parameters
- $classes : string
Return values
staticsetDataAttributes()
public
setDataAttributes(array<string|int, mixed> $dataAttributes) : static
Parameters
- $dataAttributes : array<string|int, mixed>
Return values
staticsetHref()
public
setHref(string $href) : static
Parameters
- $href : string
Return values
staticsetTitle()
public
setTitle(string $title) : static
Parameters
- $title : string