ComponentFactory

Read onlyYes

Factory for creating backend template components, e.g. buttons.

This ComponentFactory serves as the central location for all component creation in the backend, providing both pre-configured components for common patterns and basic component factory methods.

Currently focused on button creation, but designed to be extensible for other component types (menus, breadcrumbs, etc.) in the future.

This reduces boilerplate code and ensures consistent UX across the backend by providing standardized component configurations for recurring use cases.

Example - Creating a back button:

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

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

    // Use pre-configured back button
    $backButton = $this->componentFactory->createBackButton($returnUrl);
    $buttonBar->addButton($backButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
}
Attributes
#[Autoconfigure]
$public: true

Table of Contents

Properties

$eventDispatcher  : EventDispatcherInterface
$iconFactory  : IconFactory
$pageRenderer  : PageRenderer

Methods

__construct()  : mixed
createBackButton()  : LinkButton
Creates a standardized "back" navigation button.
createCloseButton()  : LinkButton
Creates a standardized "close" button.
createDropDownButton()  : DropDownButton
createDropDownDivider()  : DropDownDivider
createDropDownGeneric()  : DropDownGeneric
createDropDownHeader()  : DropDownHeader
createDropDownItem()  : DropDownItem
createDropDownRadio()  : DropDownRadio
createDropDownToggle()  : DropDownToggle
createFullyRenderedButton()  : FullyRenderedButton
createGenericButton()  : GenericButton
createInputButton()  : InputButton
createLinkButton()  : LinkButton
createMenu()  : Menu
createMenuItem()  : MenuItem
createQrCodeButton()  : GenericButton
Creates a standardized QR code button that opens a modal with a QR code for the given URL.
createReloadButton()  : LinkButton
Creates a standardized "reload" button for reloading the current view.
createSaveButton()  : InputButton
Creates a standardized "save" button for forms.
createShortcutButton()  : ShortcutButton
createSplitButton()  : SplitButton
createViewButton()  : LinkButton
getPreviewUrlForQrCode()  : string|null
Generates a preview URL suitable for QR codes.
getLanguageService()  : LanguageService

Properties

$eventDispatcher

protected EventDispatcherInterface $eventDispatcher

Methods

createBackButton()

Creates a standardized "back" navigation button.

public createBackButton(string|UriInterface $returnUrl) : LinkButton
Parameters
$returnUrl : string|UriInterface
Return values
LinkButton

createCloseButton()

Creates a standardized "close" button.

public createCloseButton(string|UriInterface $closeUrl) : LinkButton

Similar to back button but uses "actions-close" icon and "Close" label. Typically used for closing detail views or modal-like overlays.

Parameters
$closeUrl : string|UriInterface
Return values
LinkButton

createQrCodeButton()

Creates a standardized QR code button that opens a modal with a QR code for the given URL.

public createQrCodeButton(string|UriInterface $previewUrl[, bool $showCopyUrl = true ]) : GenericButton

Uses the typo3-qrcode-modal-button web component which displays a scannable QR code in a modal dialog. The QR code can be downloaded as PNG or SVG.

Parameters
$previewUrl : string|UriInterface

The URL to encode in the QR code

$showCopyUrl : bool = true

Whether to show the URL field with copy button in the modal

Return values
GenericButton

createReloadButton()

Creates a standardized "reload" button for reloading the current view.

public createReloadButton(string|UriInterface $requestUri) : LinkButton

Uses "actions-refresh" icon without a displayed label.

Note: As of TYPO3 v14, the reload button is automatically added to all modules by default. Controllers only need to manually create this button if they need custom reload behavior. In that case, use DocHeaderComponent::disableAutomaticReloadButton() to prevent the automatic one from being added.

Parameters
$requestUri : string|UriInterface
Return values
LinkButton

createSaveButton()

Creates a standardized "save" button for forms.

public createSaveButton([string $formName = '' ]) : InputButton

Returns an InputButton configured with:

  • "actions-document-save" icon
  • Translated "Save" label (shown as text)
  • name="_savedok" and value="1"
  • Associated with the specified form
Parameters
$formName : string = ''

The HTML form ID this button belongs to

Return values
InputButton

Fully configured save button

createViewButton()

public createViewButton([array<string|int, mixed> $previewDataAttributes = [] ]) : LinkButton
Parameters
$previewDataAttributes : array<string|int, mixed> = []
Return values
LinkButton

getPreviewUrlForQrCode()

Generates a preview URL suitable for QR codes.

public getPreviewUrlForQrCode(int $pageId, int $languageId[, string|UriInterface|null $fallbackUrl = null ]) : string|null

Dispatches the ModifyPreviewUrlForQrCodeEvent to allow extensions (e.g., workspaces) to provide alternative URLs. For example, the workspaces extension can provide a URL with ADMCMD_prev parameter that works without backend authentication.

Parameters
$pageId : int
$languageId : int
$fallbackUrl : string|UriInterface|null = null

Fallback URL if no listener modifies the URL

Return values
string|null

        
On this page

Search results