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 PreviewUriBuilder
from building
the URI based on the parameters.
Note
The overwritten parameters are used for building the URI and are also passed
to the AfterPagePreviewUriGeneratedEvent. They however do not
overwrite the related class properties in PreviewUriBuilder
.
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
(PsrHttpMessageUriInterface uri)¶ Parameters: - $uri (PsrHttpMessageUriInterface) – the uri
-
getPreviewUri
()¶ Return type: Psr\Http\Message\UriInterface
-
isPropagationStopped
()¶ Return type: bool
-
getPageId
()¶ Return type: int
-
setPageId
(int pageId)¶ Parameters: - $pageId (int) – the pageId
-
getLanguageId
()¶ Return type: int
-
setLanguageId
(int languageId)¶ Parameters: - $languageId (int) – the languageId
-
getRootline
()¶ Return type: array
-
setRootline
(array rootline)¶ Parameters: - $rootline (array) – the rootline
-
getSection
()¶ Return type: string
-
setSection
(string section)¶ Parameters: - $section (string) – the section
-
getAdditionalQueryParameters
()¶ Return type: array
-
setAdditionalQueryParameters
(array additionalQueryParameters)¶ Parameters: - $additionalQueryParameters (array) – the additionalQueryParameters
-
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-parameters'
method: 'modifyParameters'
The corresponding event listener class:
use TYPO3\CMS\Backend\Routing\Event\BeforePagePreviewUriGeneratedEvent;
final class MyEventListener
{
public function modifyParameters(BeforePagePreviewUriGeneratedEvent $event): void
{
// Add custom query parameter before URI generation
$event->setAdditionalQueryParameters(
array_replace_recursive(
$event->getAdditionalQueryParameters(),
['myParam' => 'paramValue']
)
);
}
}