PageContext

final readonly class \TYPO3\CMS\Backend\Context\PageContext

Generic page context for all backend modules working with pages ("id" parameter and page-tree navigation component).

This context is added to the backend request by the PSR-15 "PageContextInitialization" middleware. Replaces the module-specific duplication of language handling, page information, and site context.

Contains shared data needed across Layout Module, Records Module, etc. Does NOT contain module-specific rendering configuration.

This is a DOMAIN object and should NOT contain HTTP infrastructure concerns like ServerRequestInterface.

Access Handling: If the user has no access to the requested page, pageRecord will be null. Controllers should check $pageContext->isAccessible() before processing.

Usage: $pageContext = $request->getAttribute('pageContext'); if (!$pageContext->isAccessible()) { // Show no access page return $view->renderResponse('NoAccess'); } $selectedLanguages = $pageContext->selectedLanguageIds; $languageInfo = $pageContext->languageInformation; $rootLine = $pageContext->rootLine; $pageTsConfig = $pageContext->pageTsConfig; $moduleTsConfig = $pageContext->getModuleTsConfig('web_layout');

Table of Contents

Properties

$languageInformation  : PageLanguageInformation
$pageId  : int
$pagePermissions  : Permission
$pageRecord  : array|null
$pageTsConfig  : array
$rootLine  : array
$selectedLanguageIds  : array
$site  : SiteInterface

Methods

__construct()  : mixed
getModuleTsConfig()  : array
This is a convenience method to easily access mod.{module}.* configuration.
getPageTitle()  : string
Get page title (localized if translation exists).
getPrimaryLanguageId()  : int
Get primary selected language for single-language views.
hasMultipleLanguagesSelected()  : bool
Check if multiple languages are currently selected.
isAccessible()  : bool
Check if user has access to the page.
isDefaultLanguageSelected()  : bool
isLanguageSelected()  : bool

Properties

$selectedLanguageIds

public array $selectedLanguageIds

Methods

__construct()

public __construct(int $pageId, array|null $pageRecord, SiteInterface $site, array $rootLine, array $pageTsConfig, int[] $selectedLanguageIds, PageLanguageInformation $languageInformation, Permission $pagePermissions) : mixed

Parameters

$pageId : int

Page ID (always preserved, even if no access)

$pageRecord : array|null

Page record from readPageAccess (null if no access)

$site : SiteInterface
$rootLine : array

Page rootline including the page itself (empty array if no access)

$pageTsConfig : array

PageTSconfig array (dots removed, overlaid by user permissions, falls back to page 0 if no access)

$selectedLanguageIds : int[]

Selected language IDs (resolved and validated)

$languageInformation : PageLanguageInformation

Complete language information for this page

$pagePermissions : Permission

User's permissions for this page (calculated from backendUser->calcPerms)

getModuleTsConfig()

This is a convenience method to easily access mod.{module}.* configuration.

public getModuleTsConfig(string $module) : array

Parameters

$module : string

Return values

array

getPageTitle()

Get page title (localized if translation exists).

public getPageTitle([int|null $languageId = null ]) : string

Parameters

$languageId : int|null = null

Language ID (null = primary selected language)

Return values

string

getPrimaryLanguageId()

Get primary selected language for single-language views.

public getPrimaryLanguageId() : int

Logic:

  • If exactly 1 non-default language is selected → use that translation
  • If 0 or 2+ non-default languages are selected → use default (0)

This ensures that when switching from multi-language to single-language view, the user's focused translation is preserved (when they had one selected).

Return values

int —

Primary language ID

hasMultipleLanguagesSelected()

Check if multiple languages are currently selected.

public hasMultipleLanguagesSelected() : bool

This is useful for determining if comparison/multi-column view should be shown.

Return values

bool

isAccessible()

Check if user has access to the page.

public isAccessible() : bool

Returns false if user has no access to the requested page. Controllers should check this before processing page-specific operations.

Return values

bool

isDefaultLanguageSelected()

public isDefaultLanguageSelected() : bool

Return values

bool

isLanguageSelected()

public isLanguageSelected(int $languageId) : bool

Parameters

$languageId : int

Return values

bool
On this page