Feature: Backend environment builder
Description
The environment builder supports building backend environments for
Application, next to frontend environments. A
Backend is shipped for TYPO3 v12 and v13 and selected
automatically by the Environment for a backend build context.
For a selected page id the backend environment builder assembles a faithful backend environment, mirroring what the backend middleware chain produces during an HTTP request:
- a backend PSR-7 request (
applicationTypebackend,normalizedParamsand the resolvedsite), - a backend user — the one referenced by the build context, or a synthetic in-memory admin by default,
- a language service created from the backend user's preferences,
- a context carrying the
backend.userandworkspaceaspects.
The State provides two optional, backend-only options:
backend– the backend user to load into the environment.User Id nulluses a synthetic in-memory admin that needs nobe_usersrecord; a uid loads that existing backend user with its groups, permissions and user TSconfig.workspace– the workspace to operate in.Id nulldefaults to the live workspace.
The public State provides a language /
with accessor, and the state manager backs up, applies
and restores $GLOBALS alongside the request, TSFE and backend
user.
Example
use FGTCLB\EnvironmentStateManager\StateBuildContext;
use FGTCLB\EnvironmentStateManager\StateManagerInterface;
use TYPO3\CMS\Core\Http\ApplicationType;
final class MyService
{
public function __construct(
private readonly StateManagerInterface $stateManager,
) {}
public function run(): void
{
$stateBuildContext = new StateBuildContext(
applicationType: ApplicationType::BACKEND,
pageId: 42,
);
$this->stateManager->execute($stateBuildContext, function () {
// Runs within the backend environment built for page 42.
});
}
}
See the Developer Corner for details.