BeforePagePreviewUriGeneratedEvent 

The \TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent is executed in \TYPO3\CMS\Backend\Routing->buildUri() , before the preview URI is actually built. It allows to either adjust the parameters, such as the page id or the language id, or to set a custom preview URI, which will then stop the event propagation and also prevents \TYPO3\CMS\Backend\Routing\PreviewUriBuilder from building the URI based on the parameters.

Example: Add a query parameter to the page preview URL 

EXT:my_extension/Classes/Backend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Backend\EventListener;

use TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;

#[AsEventListener(
  identifier: 'my-extension/backend/modify-parameters',
)]
final readonly class MyEventListener
{
  public function __invoke(BeforePagePreviewUriGeneratedEvent $event): void
  {
    // Add custom query parameter before URI generation
    $event->setAdditionalQueryParameters(
      array_replace_recursive(
        $event->getAdditionalQueryParameters(),
        ['myParam' => 'paramValue'],
      ),
    );
  }
}
Copied!

API 

final class BeforePagePreviewUriGeneratedEvent
Fully qualified name
\TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent

Listeners to this event will be able to modify the corresponding parameters, before the page preview URI is being generated, when linking to a page in the frontend.

setPreviewUri(\Psr\Http\Message\UriInterface $uri)
param $uri

the uri

getPreviewUri()
Returns
?\Psr\Http\Message\UriInterface
isPropagationStopped()
Returns
bool
getPageId()
Returns
int
setPageId(int $pageId)
param $pageId

the pageId

getLanguageId()
Returns
int
setLanguageId(int $languageId)
param $languageId

the languageId

getRootline()
Returns
array
setRootline(array $rootline)
param $rootline

the rootline

getSection()
Returns
string
setSection(string $section)
param $section

the section

getAdditionalQueryParameters()
Returns
array
setAdditionalQueryParameters(array $additionalQueryParameters)
param $additionalQueryParameters

the additionalQueryParameters

getContext()
Returns
\TYPO3\CMS\Core\Context\Context
getOptions()
Returns
array