Issue Bug Closed

#109532Derive workspace preview handling from event context

Matthias Vogel 04/09/26, 15:23 updated 04/21/26, 11:30

Description

The workspace hook in typo3/sysext/workspaces/Classes/Hook/BackendUtilityHook.php decides early whether preview URI processing is
needed. Reading the workspace from the event context makes that
decision depend on the current preview state instead of the backend
user object.

Reviews 2

History 46

  1. Matthias Vogel commented <span data-processor="relativetime" data-value="2026-04-13T08:35:12+00:00" > 04/13/26, 08:35 </span>

    Background

    TYPO3 Core provides PreviewUriBuilder to generate frontend preview URLs for pages, including workspace-aware previews. Extensions may use this API when they need to embed or load a regular frontend preview.

    In this case, the extension expects a plain frontend preview URL, not a workspace compare or split preview. However, preview URL generation is still affected by the active backend workspace of the current user.

    The problem becomes visible in code like this:

    $previewUriBuilder = PreviewUriBuilder::create($this->pageRecord->getRawRecord()->toArray())
        ->withAdditionalQueryParameters($parameters);
    $uri = $previewUriBuilder->buildUri();

    An extension may try to avoid workspace influence by explicitly building the URI with a context that has no workspace aspect:

    $previewUriBuilder = PreviewUriBuilder::create($this->pageRecord->getRawRecord()->toArray())
        ->withAdditionalQueryParameters($parameters);
    
    $context = clone $this->context;
    $context->unsetAspect('workspace');
    
    $uri = $previewUriBuilder->buildUri(context: $context);

    However, this is currently not sufficient in all cases, because workspace state is still effectively derived from the backend user.

    As a workaround, extensions currently need to temporarily reset $GLOBALS['BE_USER']->workspace before calling buildUri() :

    $previewUriBuilder = PreviewUriBuilder::create($this->pageRecord->getRawRecord()->toArray())
        ->withAdditionalQueryParameters($parameters);
    
    $workspace = $this->getBackendUser()->workspace;
    $this->getBackendUser()->workspace = 0;
    try {
        $uri = $previewUriBuilder->buildUri();
    } finally {
        $this->getBackendUser()->workspace = $workspace;
    }

    From a Core perspective, this indicates that PreviewUriBuilder is not yet fully isolated from backend user workspace state.

    Expected behavior

    When an extension calls PreviewUriBuilder with a context where the workspace aspect has been removed, TYPO3 Core should generate a plain frontend preview URL only.

    Passing a workspace-neutral context should be sufficient to guarantee that no active backend workspace is applied implicitly. Preview URL generation should be deterministic and should not depend on $GLOBALS['BE_USER']->workspace when an explicit context is provided.

  2. Christian Kuhn commented <span data-processor="relativetime" data-value="2026-04-13T10:41:33+00:00" > 04/13/26, 10:41 </span>

    note: this came up with ext:visual_editor, where the view module needs to get a preview without triggering the workspace split view.

  3. Matthias Vogel commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-04-13T11:35:09+00:00" > 04/13/26, 11:35 </span>

    Applied in changeset commit:bfac1c8848d8a5ad85d04076c06085e5721325fd.