BeforePageIsRetrievedEvent

New in version 13.0: This event serves as a more powerful replacement for the removed $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'] hook.

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 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\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, you can also register an event listener via the Configuration/Services.yaml file. Have a look into the section Implementing an event listener in your extension.

API

class 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()
Return type

TYPO3\CMS\Core\Domain\Page

setPage(TYPO3\\CMS\\Core\\Domain\\Page $page)
Parameters
  • $page (TYPO3\CMS\Core\Domain\Page) -- the page

hasPage()
Return type

bool

getPageId()
Return type

int

setPageId(int $pageId)
Parameters
  • $pageId (int) -- the pageId

isGroupAccessCheckSkipped()
Return type

bool

getContext()
Return type

TYPO3\CMS\Core\Context\Context