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 = []

$showLabelText

protected bool $showLabelText = false

$size

protected ButtonSize $size = \TYPO3\CMS\Backend\Template\Components\Buttons\ButtonSize::SMALL

Methods

__toString()

public __toString() : string
Return values
string

getAttributes()

public getAttributes() : array<string, string>
Return values
array<string, string>

getClasses()

public getClasses() : string
Return values
string

getHref()

public getHref() : string|null
Return values
string|null

getLabel()

public getLabel() : string|null
Return values
string|null

getShowLabelText()

public getShowLabelText() : bool
Return values
bool

getTag()

public getTag() : string
Return values
string

getTitle()

public getTitle() : string|null
Return values
string|null

getType()

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
static

setClasses()

public setClasses(string $classes) : static
Parameters
$classes : string
Return values
static

setHref()

public setHref(string|null $href) : static
Parameters
$href : string|null
Return values
static

setIcon()

public setIcon(Icon|null $icon) : static
Parameters
$icon : Icon|null
Return values
static

setLabel()

public setLabel(string|null $label) : static
Parameters
$label : string|null
Return values
static

setShowLabelText()

public setShowLabelText(bool $showLabelText) : static
Parameters
$showLabelText : bool
Return values
static

setTag()

public setTag(string $tag) : static
Parameters
$tag : string
Return values
static

setTitle()

public setTitle(string|null $title) : static
Parameters
$title : string|null
Return values
static

getAttributesString()

protected getAttributesString() : string
Return values
string

        
On this page

Search results