ComponentFactory
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
$iconFactory
protected
IconFactory
$iconFactory
$pageRenderer
protected
PageRenderer
$pageRenderer
Methods
__construct()
public
__construct(IconFactory $iconFactory, EventDispatcherInterface $eventDispatcher, PageRenderer $pageRenderer) : mixed
Parameters
- $iconFactory : IconFactory
- $eventDispatcher : EventDispatcherInterface
- $pageRenderer : PageRenderer
createBackButton()
Creates a standardized "back" navigation button.
public
createBackButton(string|UriInterface $returnUrl) : LinkButton
Parameters
- $returnUrl : string|UriInterface
Return values
LinkButtoncreateCloseButton()
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
LinkButtoncreateDropDownButton()
public
createDropDownButton() : DropDownButton
Return values
DropDownButtoncreateDropDownDivider()
public
createDropDownDivider() : DropDownDivider
Return values
DropDownDividercreateDropDownGeneric()
public
createDropDownGeneric() : DropDownGeneric
Return values
DropDownGenericcreateDropDownHeader()
public
createDropDownHeader() : DropDownHeader
Return values
DropDownHeadercreateDropDownItem()
public
createDropDownItem() : DropDownItem
Return values
DropDownItemcreateDropDownRadio()
public
createDropDownRadio() : DropDownRadio
Return values
DropDownRadiocreateDropDownToggle()
public
createDropDownToggle() : DropDownToggle
Return values
DropDownTogglecreateFullyRenderedButton()
public
createFullyRenderedButton() : FullyRenderedButton
Return values
FullyRenderedButtoncreateGenericButton()
public
createGenericButton() : GenericButton
Return values
GenericButtoncreateInputButton()
public
createInputButton() : InputButton
Return values
InputButtoncreateLinkButton()
public
createLinkButton() : LinkButton
Return values
LinkButtoncreateMenu()
public
createMenu() : Menu
Return values
MenucreateMenuItem()
public
createMenuItem() : MenuItem
Return values
MenuItemcreateQrCodeButton()
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
GenericButtoncreateReloadButton()
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
LinkButtoncreateSaveButton()
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
createShortcutButton()
public
createShortcutButton() : ShortcutButton
Return values
ShortcutButtoncreateSplitButton()
public
createSplitButton() : SplitButton
Return values
SplitButtoncreateViewButton()
public
createViewButton([array<string|int, mixed> $previewDataAttributes = [] ]) : LinkButton
Parameters
- $previewDataAttributes : array<string|int, mixed> = []
Return values
LinkButtongetPreviewUrlForQrCode()
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|nullgetLanguageService()
protected
getLanguageService() : LanguageService