ModuleTemplate

final class \TYPO3\CMS\Backend\Template\ModuleTemplate

Implements
ViewInterface, ResponsableViewInterface
Uses
PageRendererBackendSetupTrait

A class taking care of the "outer" HTML of a module, especially the doc header and other related parts.

Table of Contents

Interfaces

ViewInterface
A generic view interface.
ResponsableViewInterface
An optional addition to ViewInterface that allows getting a PSR-7 Response directly.

Properties

$bodyTag  : string
$docHeaderComponent  : DocHeaderComponent
$extensionConfiguration  : ExtensionConfiguration
$flashMessageQueue  : FlashMessageQueue
$flashMessageService  : FlashMessageService
$formTag  : string
$iconFactory  : IconFactory
$moduleClass  : string
$moduleId  : string
$moduleName  : string
$moduleProvider  : ModuleProvider
$pageRenderer  : PageRenderer
$request  : ServerRequestInterface
$title  : string
$uiBlock  : bool
$uriBuilder  : UriBuilder
$view  : ViewInterface

Methods

__construct()  : mixed
Init PageRenderer and properties.
addFlashMessage()  : self
Creates a message object and adds it to the FlashMessageQueue.
assign()  : self
Add a variable to the view data collection.
assignMultiple()  : self
Add multiple variables to the view data collection.
getDocHeaderComponent()  : DocHeaderComponent
Get the DocHeader. Can be used in controllers to add custom buttons / menus / ... to the doc header.
makeDocHeaderModuleMenu()  : self
Generates a menu in the docheader to access third-level modules
render()  : string
Render the module.
renderResponse()  : ResponseInterface
Render the module and create an HTML 200 response from it. This is a lazy shortcut so controllers don't need to take care of this in the backend.
setBodyTag()  : self
Set to something like '<body id="foo">' when a special body tag is needed.
setFlashMessageQueue()  : self
ModuleTemplate by default uses queue 'core.template.flashMessages'. Modules may want to maintain an own queue. Use this method to render flash messages of a non-default queue at the default position in module HTML output. Call this method *before* adding single messages with addFlashMessage().
setForm()  : self
A "<form>" tag encapsulating the entire module, including doc-header.
setModuleClass()  : self
Optional 'class="module {moduleClass}"' on first <div> in body.
setModuleId()  : self
Optional 'data-module-id="{moduleId}"' on first <div> in body.
setModuleName()  : self
Optional 'data-module-name="{moduleName}"' on first <div> in body.
setTitle()  : self
Title string of the module: "My module · Edit view"
setUiBlock()  : self
UI block is a spinner shown during browser rendering phase of the module, automatically removed when rendering finished. This is done by default, but the UI block can be turned off when needed for whatever reason.
dispatchNotificationMessages()  : void
Dispatches all messages in a special FlashMessageQueue to the PageRenderer to be rendered as inline notifications
getBackendFavicon()  : string
Retrieves configured favicon for backend with fallback.
getBackendUser()  : BackendUserAuthentication
getLanguageService()  : LanguageService
getNormalizedParams()  : NormalizedParams
getUriForFileName()  : string
Returns the uri of a relative reference, resolves the "EXT:" prefix (way of referring to files inside extensions) and checks that the file is inside the project root of the TYPO3 installation
loadStylesheets()  : void
Load all registered stylesheets from $GLOBALS['TYPO3_CONF_VARS']['BE']['stylesheets']
prepareRender()  : void
setUpBasicPageRendererForBackend()  : void
Sets mandatory parameters for the PageRenderer.

Properties

$bodyTag

protected string $bodyTag = '<body>'

$moduleClass

protected string $moduleClass = ''

$moduleName

protected string $moduleName = ''

$request read-only

protected ServerRequestInterface $request

Methods

__construct()

Init PageRenderer and properties.

public __construct(PageRenderer $pageRenderer, IconFactory $iconFactory, UriBuilder $uriBuilder, ModuleProvider $moduleProvider, FlashMessageService $flashMessageService, ExtensionConfiguration $extensionConfiguration, ViewInterface $view, ServerRequestInterface $request) : mixed

Parameters

$pageRenderer : PageRenderer
$iconFactory : IconFactory
$uriBuilder : UriBuilder
$moduleProvider : ModuleProvider
$flashMessageService : FlashMessageService
$extensionConfiguration : ExtensionConfiguration
$view : ViewInterface
$request : ServerRequestInterface

addFlashMessage()

Creates a message object and adds it to the FlashMessageQueue.

public addFlashMessage(string $messageBody[, string $messageTitle = '' ][, ContextualFeedbackSeverity $severity = ContextualFeedbackSeverity::OK ][, bool $storeInSession = true ]) : self

These messages are automatically rendered when the view is rendered.

Parameters

$messageBody : string
$messageTitle : string = ''
$severity : ContextualFeedbackSeverity = ContextualFeedbackSeverity::OK
$storeInSession : bool = true

Return values

self

assign()

Add a variable to the view data collection.

public assign(string $key, mixed $value) : self

Parameters

$key : string
$value : mixed

Return values

self

assignMultiple()

Add multiple variables to the view data collection.

public assignMultiple(array $values) : self

Parameters

$values : array

Array of string keys with mixed-type values.

Return values

self

makeDocHeaderModuleMenu()

Generates a menu in the docheader to access third-level modules

public makeDocHeaderModuleMenu([array $additionalQueryParams = [] ]) : self

Parameters

$additionalQueryParams : array = []

Return values

self

render()

Render the module.

public render([string $templateFileName = '' ]) : string

Parameters

$templateFileName : string = ''

Return values

string

renderResponse()

Render the module and create an HTML 200 response from it. This is a lazy shortcut so controllers don't need to take care of this in the backend.

public renderResponse([string $templateFileName = '' ]) : ResponseInterface

Parameters

$templateFileName : string = ''

Return values

ResponseInterface

setBodyTag()

Set to something like '<body id="foo">' when a special body tag is needed.

public setBodyTag(string $bodyTag) : self

Parameters

$bodyTag : string

Return values

self

setFlashMessageQueue()

ModuleTemplate by default uses queue 'core.template.flashMessages'. Modules may want to maintain an own queue. Use this method to render flash messages of a non-default queue at the default position in module HTML output. Call this method *before* adding single messages with addFlashMessage().

public setFlashMessageQueue(FlashMessageQueue $flashMessageQueue) : self

Parameters

$flashMessageQueue : FlashMessageQueue

Return values

self

setForm()

A "<form>" tag encapsulating the entire module, including doc-header.

public setForm([string $formTag = '' ]) : self

Parameters

$formTag : string = ''

Return values

self

setModuleClass()

Optional 'class="module {moduleClass}"' on first <div> in body.

public setModuleClass(string $moduleClass) : self

Can be helpful styling modules.

Parameters

$moduleClass : string

Return values

self

setModuleId()

Optional 'data-module-id="{moduleId}"' on first <div> in body.

public setModuleId(string $moduleId) : self

Can be helpful in JavaScript.

Parameters

$moduleId : string

Return values

self

setModuleName()

Optional 'data-module-name="{moduleName}"' on first <div> in body.

public setModuleName(string $moduleName) : self

Can be helpful in JavaScript.

Parameters

$moduleName : string

Return values

self

setTitle()

Title string of the module: "My module · Edit view"

public setTitle(string $title[, string $context = '' ]) : self

Parameters

$title : string
$context : string = ''

Return values

self

setUiBlock()

UI block is a spinner shown during browser rendering phase of the module, automatically removed when rendering finished. This is done by default, but the UI block can be turned off when needed for whatever reason.

public setUiBlock(bool $uiBlock) : self

Parameters

$uiBlock : bool

Return values

self

dispatchNotificationMessages()

Dispatches all messages in a special FlashMessageQueue to the PageRenderer to be rendered as inline notifications

protected dispatchNotificationMessages() : void

getBackendFavicon()

Retrieves configured favicon for backend with fallback.

protected getBackendFavicon(ExtensionConfiguration $extensionConfiguration, ServerRequestInterface $request) : string

Parameters

$extensionConfiguration : ExtensionConfiguration
$request : ServerRequestInterface

Return values

string

getUriForFileName()

Returns the uri of a relative reference, resolves the "EXT:" prefix (way of referring to files inside extensions) and checks that the file is inside the project root of the TYPO3 installation

protected getUriForFileName(ServerRequestInterface $request, string $filename) : string

Parameters

$request : ServerRequestInterface
$filename : string

The input filename/filepath to evaluate

Return values

string —

Returns the filename of $filename if valid, otherwise blank string.

loadStylesheets()

Load all registered stylesheets from $GLOBALS['TYPO3_CONF_VARS']['BE']['stylesheets']

protected loadStylesheets(PageRenderer $pageRenderer) : void

Parameters

$pageRenderer : PageRenderer

prepareRender()

protected prepareRender(string $templateFileName) : void

Parameters

$templateFileName : string
On this page