BeforePageIsRetrievedEvent

New in version 13.0

The PSR-14 event \TYPO3\CMS\Core\Domain\Event\BeforePageIsRetrievedEvent allows to modify the resolving of page records within \TYPO3\CMS\Core\Domain\PageRepository->getPage().

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

EXT:my_extension/Classes/Domain/Access/MyEventListener.php
<?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]));
        }
    }
}
Copied!

New in version 13.0

API

class BeforePageIsRetrievedEvent
Fully qualified name
\TYPO3\CMS\Core\Domain\Event\BeforePageIsRetrievedEvent

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.

getPage ( )
Returns
?\TYPO3\CMS\Core\Domain\Page
setPage ( \TYPO3\CMS\Core\Domain\Page $page)
param $page

the page

hasPage ( )
Returns
bool
getPageId ( )
Returns
int
setPageId ( int $pageId)
param $pageId

the pageId

skipGroupAccessCheck ( )
respectGroupAccessCheck ( )
isGroupAccessCheckSkipped ( )
Returns
bool
getContext ( )
Returns
\TYPO3\CMS\Core\Context\Context