ButtonBar

Container for managing buttons in the backend module document header.

The ButtonBar organizes buttons into two positions (left and right) with multiple groups, allowing precise control over button placement and visual grouping.

Buttons are organized in a three-level structure:

  1. Position: LEFT or RIGHT side of the header
  2. Group: Numerical groups within each position (1, 2, 3, etc.)
  3. Individual buttons within each group

Groups are rendered with visual spacing between them, allowing logical grouping of related actions. Lower group numbers appear first (left-to-right, or top-to-bottom on mobile).

Example - Using pre-configured buttons from ComponentFactory:

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

public function myAction(): ResponseInterface
{
    $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();

    // Use pre-configured save button
    $saveButton = $this->componentFactory->createSaveButton('editform');
    $buttonBar->addButton($saveButton, ButtonBar::BUTTON_POSITION_LEFT, 1);

    // Use pre-configured back button
    $backButton = $this->componentFactory->createBackButton($returnUrl);
    $buttonBar->addButton($backButton, ButtonBar::BUTTON_POSITION_LEFT, 2);
}

Example - Creating custom buttons with ComponentFactory:

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

public function myAction(): ResponseInterface
{
    $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();

    // Create custom link button
    $customButton = $this->componentFactory->createLinkButton()
        ->setHref('/custom-action')
        ->setTitle('Custom Action')
        ->setIcon($iconFactory->getIcon('actions-custom'));
    $buttonBar->addButton($customButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
}

Example - Buttons with automatic positioning:

// ShortcutButton implements PositionInterface and positions itself automatically
$shortcutButton = $this->componentFactory->createShortcutButton()
    ->setRouteIdentifier('my_module')
    ->setDisplayName('My Module');
$buttonBar->addButton($shortcutButton); // Position and group are automatic

Example - Dropdown button:

$dropdownButton = $this->componentFactory->createDropDownButton()
    ->setLabel('Actions')
    ->setIcon($iconFactory->getIcon('actions-menu'));

$item1 = $this->componentFactory->createDropDownItem()
    ->setLabel('Edit')
    ->setHref('/edit');
$dropdownButton->addItem($item1);

$item2 = $this->componentFactory->createDropDownItem()
    ->setLabel('Delete')
    ->setHref('/delete');
$dropdownButton->addItem($item2);

$buttonBar->addButton($dropdownButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
Tags
phpstan-type

Buttons array<self::BUTTON_POSITION_*, array<int, list<ButtonInterface>>>

Attributes
#[Autoconfigure]
$public: true

Table of Contents

Constants

BUTTON_POSITION_LEFT  : mixed = 'left'
Position constant for left side of the button bar
BUTTON_POSITION_RIGHT  : mixed = 'right'
Position constant for right side of the button bar

Properties

$buttons  : Buttons
Internal array of all registered buttons
$eventDispatcher  : EventDispatcherInterface

Methods

__construct()  : mixed
addButton()  : static
Add a new button
getButtons()  : array<string|int, mixed>
Returns an associative array of all buttons in the form of ButtonPosition > ButtonGroup > Button
hasButtonOfType()  : bool
Checks whether a button of the specified type has been added to the button bar.

Constants

BUTTON_POSITION_LEFT

Position constant for left side of the button bar

public mixed BUTTON_POSITION_LEFT = 'left'

BUTTON_POSITION_RIGHT

Position constant for right side of the button bar

public mixed BUTTON_POSITION_RIGHT = 'right'

Properties

$buttons

Internal array of all registered buttons

protected Buttons $buttons = []

$eventDispatcher read-only

protected EventDispatcherInterface $eventDispatcher

Methods

__construct()

public __construct(EventDispatcherInterface $eventDispatcher) : mixed
Parameters
$eventDispatcher : EventDispatcherInterface

addButton()

Add a new button

public addButton(ButtonInterface $button[, self::BUTTON_POSITION_* $buttonPosition = self::BUTTON_POSITION_LEFT ][, int $buttonGroup = 1 ]) : static

Buttons implementing PositionInterface will automatically use their own predefined position and group, ignoring the $buttonPosition and $buttonGroup parameters. This ensures buttons like ShortcutButton always appear in their designated location.

Parameters
$button : ButtonInterface

The Button Object to add

$buttonPosition : self::BUTTON_POSITION_* = self::BUTTON_POSITION_LEFT

Position of the button (left/right). Ignored if button implements PositionInterface.

$buttonGroup : int = 1

Buttongroup of the button. Ignored if button implements PositionInterface.

Tags
throws
InvalidArgumentException

In case a button is not valid

Return values
static

getButtons()

Returns an associative array of all buttons in the form of ButtonPosition > ButtonGroup > Button

public getButtons(ServerRequestInterface $request) : array<string|int, mixed>
Parameters
$request : ServerRequestInterface
Return values
array<string|int, mixed>

hasButtonOfType()

Checks whether a button of the specified type has been added to the button bar.

public hasButtonOfType(ButtonInterface> $buttonClassName) : bool

This is primarily used for backwards compatibility detection to prevent duplicate automatic buttons when controllers manually add them.

Parameters
$buttonClassName : ButtonInterface>

Fully qualified button class name

Return values
bool

True if a button of this type exists, false otherwise

On this page

Search results