PageContextFactory

Read onlyYes
FinalYes

Factory for creating PageContext instances.

This is the SINGLE entry point for creating page contexts across all backend modules. It centralizes the logic for:

  • Resolving language selection with fallback chain
  • Validating languages against available languages
  • Permission checks
  • Fetching language information
Internal

Table of Contents

Methods

__construct()  : mixed
createFromRequest()  : PageContext
Create PageContext from request and page ID.
createWithLanguages()  : PageContext
Create PageContext with specific languages (no fallback resolution).

Methods

createFromRequest()

Create PageContext from request and page ID.

public createFromRequest(ServerRequestInterface $request, int $pageId, BackendUserAuthentication $backendUser) : PageContext

This method:

  1. Validates page access (returns context with null pageId/pageRecord if no access)
  2. Fetches language information for the page
  3. Resolves selected languages with fallback chain
  4. Validates selected languages against existing translations on this page
  5. Falls back to default language if no valid languages selected
  6. Stores preference if explicitly changed via request (preserves across pages)
  7. Creates and returns the PageContext

Language validation ensures that only languages with actual translations on the current page are included in selectedLanguageIds. This guarantees that getPrimaryLanguageId() always returns a valid language for the current page.

User preferences are preserved: selecting L=1 on PageA stores the preference, navigating to PageB without L=1 shows L=0, returning to PageA restores L=1.

Access Handling: If the user has no access to the requested page, a PageContext is still returned but with pageId=null and pageRecord=null. Controllers should check isAccessible().

Parameters
$request : ServerRequestInterface
$pageId : int

Page ID to create context for

$backendUser : BackendUserAuthentication
Return values
PageContext

createWithLanguages()

Create PageContext with specific languages (no fallback resolution).

public createWithLanguages(ServerRequestInterface $request, int $pageId, array<string|int, mixed> $languageIds, BackendUserAuthentication $backendUser) : PageContext

This is useful for testing or to explicitly set languages without going through the fallback chain.

Access Handling: If the user has no access to the requested page, a PageContext is still returned but with pageId=null and pageRecord=null. Controllers should check isAccessible().

Parameters
$request : ServerRequestInterface
$pageId : int
$languageIds : array<string|int, mixed>
$backendUser : BackendUserAuthentication
Return values
PageContext

        
On this page

Search results