BeforePagePreviewUriGeneratedEvent

New in version 12.0

This PSR-14 event replaces the $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass'] preProcess hook.

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

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!

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, or if you need to be compatible with older TYPO3 versions, you can also register an event listener via the Configuration/Services.yaml file. Switch to an older version of this page for an example or have a look at the section Implementing an event listener in your extension.

API

class \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 Psr\\Http\\Message\\UriInterface $uri

the uri

getPreviewUri ( )
returntype

Psr\Http\Message\UriInterface

isPropagationStopped ( )
returntype

bool

getPageId ( )
returntype

int

setPageId ( int $pageId)
param int $pageId

the pageId

getLanguageId ( )
returntype

int

setLanguageId ( int $languageId)
param int $languageId

the languageId

getRootline ( )
returntype

array

setRootline ( array $rootline)
param array $rootline

the rootline

getSection ( )
returntype

string

setSection ( string $section)
param string $section

the section

getAdditionalQueryParameters ( )
returntype

array

setAdditionalQueryParameters ( array $additionalQueryParameters)
param array $additionalQueryParameters

the additionalQueryParameters

getContext ( )
returntype

TYPO3\CMS\Core\Context\Context

getOptions ( )
returntype

array