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:
- Position: LEFT or RIGHT side of the header
- Group: Numerical groups within each position (1, 2, 3, etc.)
- 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
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
= []
$componentFactory read-only
protected
ComponentFactory
$componentFactory
$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
Return values
staticgetButtons()
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
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
Return values
ButtonInterfacemakeDropDownButton()
public
makeDropDownButton() : DropDownButton
since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createDropDownButton() instead.
Return values
DropDownButtonmakeFullyRenderedButton()
public
makeFullyRenderedButton() : FullyRenderedButton
since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createFullyRenderedButton() instead.
Return values
FullyRenderedButtonmakeGenericButton()
public
makeGenericButton() : GenericButton
since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createGenericButton() instead.
Return values
GenericButtonmakeInputButton()
public
makeInputButton() : InputButton
since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createInputButton() instead.
Return values
InputButtonmakeLinkButton()
public
makeLinkButton() : LinkButton
since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createLinkButton() instead.
Return values
LinkButtonmakeShortcutButton()
public
makeShortcutButton() : ShortcutButton
since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createShortcutButton() instead.
Return values
ShortcutButtonmakeSplitButton()
public
makeSplitButton() : SplitButton
since v14, will be removed in v15. Inject ComponentFactory and use ComponentFactory::createSplitButton() instead.