BeforePageIsRetrievedEvent
New in version 13.0
This event serves as a more powerful replacement for the removed
$GLOBALS
hook.
The PSR-14 event \TYPO3\
allows to modify the resolving of page records within
\TYPO3\
.
It can be used to alter the incoming page ID or to even fetch a fully-loaded page object before the default TYPO3 behaviour is executed, effectively bypassing the default page resolving.
Example
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Domain\Page;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Domain\Event\BeforePageIsRetrievedEvent;
use TYPO3\CMS\Core\Domain\Page;
#[AsEventListener(
identifier: 'my-extension/my-custom-page-resolver',
)]
final readonly class MyEventListener
{
public function __invoke(BeforePageIsRetrievedEvent $event): void
{
if ($event->getPageId() === 13) {
$event->setPageId(42);
return;
}
if ($event->getContext()->getPropertyFromAspect('language', 'id') > 0) {
$event->setPage(new Page(['uid' => 43]));
}
}
}
New in version 13.0
The PHP attribute \TYPO3\
has been
introduced to tag a PHP class as an event listener. Alternatively, you can also
register an event listener via the Configuration/
file. Have
a look into the section Implementing an event listener in your extension.
API
- class BeforePageIsRetrievedEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Core\ Domain\ Event\ Before Page Is Retrieved Event
Event which is fired before a page (id) is being resolved from PageRepository.
Allows to change the corresponding page ID, e.g. to resolve a different page with custom overlaying, or to fully resolve the page on your own.