PageContextFactory
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
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
__construct()
public
__construct(SharedUserPreferences $sharedPreferences, PageLanguageInformationService $languageService) : mixed
Parameters
- $sharedPreferences : SharedUserPreferences
- $languageService : PageLanguageInformationService
createFromRequest()
Create PageContext from request and page ID.
public
createFromRequest(ServerRequestInterface $request, int $pageId, BackendUserAuthentication $backendUser) : PageContext
This method:
- Validates page access (returns context with null pageId/pageRecord if no access)
- Fetches language information for the page
- Resolves selected languages with fallback chain
- Validates selected languages against existing translations on this page
- Falls back to default language if no valid languages selected
- Stores preference if explicitly changed via request (preserves across pages)
- 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
PageContextcreateWithLanguages()
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