AfterPagePreviewUriGeneratedEvent¶
New in version 12.0: This PSR-14 event replaces the
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']
postProcess hook.
The \TYPO3\CMS\Backend\Routing\Event\AfterPagePreviewUriGeneratedEvent
is executed in \TYPO3\CMS\Backend\Routing->buildUri()
, after the preview
URI has been built - or set by an event listener to
BeforePagePreviewUriGeneratedEvent. It allows to overwrite the built
preview URI. This event however does not feature the possibility to modify the
parameters, since this won’t have any effect as the preview URI is directly
returned after event dispatching and no further action is done by the
PreviewUriBuilder
.
API¶
-
class
TYPO3\CMS\Backend\Routing\Event\
AfterPagePreviewUriGeneratedEvent
¶ Listeners to this event will be able to modify the page preview URI, which had been generated for a page in the frontend.
-
setPreviewUri
(PsrHttpMessageUriInterface previewUri)¶ Parameters: - $previewUri (PsrHttpMessageUriInterface) – the previewUri
-
getPreviewUri
()¶ Return type: Psr\Http\Message\UriInterface
-
getPageId
()¶ Return type: int
-
getLanguageId
()¶ Return type: int
-
getRootline
()¶ Return type: array
-
getSection
()¶ Return type: string
-
getAdditionalQueryParameters
()¶ Return type: array
-
getContext
()¶ Return type: TYPO3\CMS\Core\Context\Context
-
getOptions
()¶ Return type: array
-
Example¶
Registration of the Event in your extensions’ Services.yaml
:
MyVendor\MyExtension\Backend\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/backend/modify-preview-uri'
method: 'modifyPreviewUri'
The corresponding event listener class:
use TYPO3\CMS\Backend\Routing\Event\AfterPagePreviewUriGeneratedEvent;
final class MyEventListener
{
public function modifyPreviewUri(AfterPagePreviewUriGeneratedEvent $event): void
{
// Add custom fragment to built preview URI
$uri = $event->getPreviewUri();
$uri = $uri->withFragment('#customFragment');
$event->setPreviewUri($uri);
}
}