GenericButton implements ButtonInterface
A flexible button type that allows rendering any HTML tag (button, anchor, or custom web components) with full control over attributes. Unlike other button types that extend AbstractButton, GenericButton implements ButtonInterface directly, providing maximum flexibility for custom implementations.
Use cases:
- Custom web components (e.g.,
) - Standard buttons with custom attributes
- Links with button styling
- Any HTML element that should appear as a button in the document header
Key features:
- Configurable HTML tag (button, a, custom elements)
- Full attribute control (href, data attributes, etc.)
- Icon and label support
- Automatic HTML escaping for security
Example - Standard button:
public function __construct(
protected readonly ComponentFactory $componentFactory,
) }
public function myAction(): ResponseInterface
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
$button = $this->componentFactory->createGenericButton()
->setTag('button')
->setLabel('Save')
->setTitle('Save changes')
->setIcon($iconFactory->getIcon('actions-save'))
->setShowLabelText(true)
->setAttributes(['type' => 'submit', 'form' => 'myForm']);
$buttonBar->addButton($button);
}
Example - Web component:
$button = $this->componentFactory->createGenericButton()
->setTag('typo3-my-action-button')
->setLabel('Custom Action')
->setIcon($iconFactory->getIcon('actions-heart'))
->setAttributes([
'url' => '/my-action',
'data-value' => '123'
]);
$buttonBar->addButton($button);
Example - Link styled as button:
$button = $this->componentFactory->createGenericButton()
->setTag('a')
->setHref('/target-page')
->setLabel('View Page')
->setTitle('Open target page')
->setIcon($iconFactory->getIcon('actions-view'));
$buttonBar->addButton($button);
Table of Contents
Interfaces
- ButtonInterface
- Interface for buttons in the document header.
Properties
- $attributes : array<string|int, mixed>
- $classes : string
- $href : string|null
- $icon : Icon|null
- $label : string
- $showLabelText : bool
- $size : ButtonSize
- $tag : string
- $title : string|null
Methods
- __toString() : string
- getAttributes() : array<string, string>
- getClasses() : string
- getHref() : string|null
- getIcon() : Icon|null
- getLabel() : string|null
- getShowLabelText() : bool
- getSize() : ButtonSize
- getTag() : string
- getTitle() : string|null
- getType() : string
- Returns the fully qualified class name as the component type identifier.
- isValid() : bool
- Validates whether the component is properly configured and can be rendered.
- render() : string
- Renders the component as an HTML string.
- setAttributes() : static
- setClasses() : static
- setHref() : static
- setIcon() : static
- setLabel() : static
- setShowLabelText() : static
- setSize() : static
- setTag() : static
- setTitle() : static
- getAttributesString() : string
Properties
$attributes
protected
array<string|int, mixed>
$attributes
= []
$classes
protected
string
$classes
= ''
$href
protected
string|null
$href
= null
$icon
protected
Icon|null
$icon
= null
$label
protected
string
$label
= ''
$showLabelText
protected
bool
$showLabelText
= false
$size
protected
ButtonSize
$size
= \TYPO3\CMS\Backend\Template\Components\Buttons\ButtonSize::SMALL
$tag
protected
string
$tag
= 'button'
$title
protected
string|null
$title
= null
Methods
__toString()
public
__toString() : string
Return values
stringgetAttributes()
public
getAttributes() : array<string, string>
Return values
array<string, string>getClasses()
public
getClasses() : string
Return values
stringgetHref()
public
getHref() : string|null
Return values
string|nullgetIcon()
public
getIcon() : Icon|null
Return values
Icon|nullgetLabel()
public
getLabel() : string|null
Return values
string|nullgetShowLabelText()
public
getShowLabelText() : bool
Return values
boolgetSize()
public
getSize() : ButtonSize
Return values
ButtonSizegetTag()
public
getTag() : string
Return values
stringgetTitle()
public
getTitle() : string|null
Return values
string|nullgetType()
Returns the fully qualified class name as the component type identifier.
public
getType() : string
This is used to identify the specific component type in validation and rendering.
Return values
string —The fully qualified class name (e.g., 'TYPO3\CMS\Backend\Template\Components\Buttons\LinkButton')
isValid()
Validates whether the component is properly configured and can be rendered.
public
isValid() : bool
Each implementing class defines its own validation rules (e.g., required fields).
Return values
bool —True if the component is valid and can be rendered, false otherwise
render()
Renders the component as an HTML string.
public
render() : string
This method should only be called after validating the component with isValid(). The returned HTML is ready to be output to the browser.
Return values
string —The rendered HTML markup
setAttributes()
public
setAttributes(array<string, string> $attributes) : static
Parameters
- $attributes : array<string, string>
Return values
staticsetClasses()
public
setClasses(string $classes) : static
Parameters
- $classes : string
Return values
staticsetHref()
public
setHref(string|null $href) : static
Parameters
- $href : string|null
Return values
staticsetIcon()
public
setIcon(Icon|null $icon) : static
Parameters
- $icon : Icon|null
Return values
staticsetLabel()
public
setLabel(string|null $label) : static
Parameters
- $label : string|null
Return values
staticsetShowLabelText()
public
setShowLabelText(bool $showLabelText) : static
Parameters
- $showLabelText : bool
Return values
staticsetSize()
public
setSize(ButtonSize $size) : static
Parameters
- $size : ButtonSize
Return values
staticsetTag()
public
setTag(string $tag) : static
Parameters
- $tag : string
Return values
staticsetTitle()
public
setTitle(string|null $title) : static
Parameters
- $title : string|null
Return values
staticgetAttributesString()
protected
getAttributesString() : string