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 = GeneralUtility::makeInstance(DropDownItem::class)
    ->setLabel('Edit')
    ->setHref('/edit');
$dropdownButton->addItem($item1);

$item2 = GeneralUtility::makeInstance(DropDownItem::class)
    ->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  = 'left'
Position constant for left side of the button bar
BUTTON_POSITION_RIGHT  = 'right'
Position constant for right side of the button bar

Properties

$buttons  : Buttons
Internal array of all registered buttons
$componentFactory  : ComponentFactory
$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
makeButton()  : ButtonInterface
Creates a new button of the given type
makeDropDownButton()  : DropDownButton
makeFullyRenderedButton()  : FullyRenderedButton
makeGenericButton()  : GenericButton
makeInputButton()  : InputButton
makeLinkButton()  : LinkButton
makeShortcutButton()  : ShortcutButton
makeSplitButton()  : SplitButton

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(ComponentFactory $componentFactory, EventDispatcherInterface $eventDispatcher) : mixed
Parameters
$componentFactory : ComponentFactory
$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() : array<string|int, mixed>
Return values
array<string|int, mixed>

makeButton()

Creates a new button of the given type

public makeButton(string $button) : ButtonInterface
Deprecated

since v14, will be removed in v15. Use GeneralUtility::makeInstance() directly or inject ComponentFactory and use its create*() methods.

Parameters
$button : string

ButtonClass to invoke. Must implement ButtonInterface

Tags
throws
InvalidArgumentException

In case a ButtonClass does not implement ButtonInterface

Return values
ButtonInterface

makeDropDownButton()

public makeDropDownButton() : DropDownButton
Deprecated

since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createDropDownButton() instead.

Return values
DropDownButton

makeFullyRenderedButton()

public makeFullyRenderedButton() : FullyRenderedButton
Deprecated

since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createFullyRenderedButton() instead.

Return values
FullyRenderedButton

makeGenericButton()

public makeGenericButton() : GenericButton
Deprecated

since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createGenericButton() instead.

Return values
GenericButton

makeInputButton()

public makeInputButton() : InputButton
Deprecated

since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createInputButton() instead.

Return values
InputButton

makeLinkButton()

public makeLinkButton() : LinkButton
Deprecated

since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createLinkButton() instead.

Return values
LinkButton

makeShortcutButton()

public makeShortcutButton() : ShortcutButton
Deprecated

since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createShortcutButton() instead.

Return values
ShortcutButton

makeSplitButton()

public makeSplitButton() : SplitButton
Deprecated

since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createSplitButton() instead.

Return values
SplitButton

        
On this page

Search results