Feature: #92780 - Introduce event after page URI generation 

See forge#92780

Description 

A new PSR-14 event \TYPO3\CMS\Core\Routing\Event\AfterPageUriGeneratedEvent is dispatched in \TYPO3\CMS\Core\Routing\PageRouter::generateUri().

The event provides access to the generated URI and the arguments passed to generateUri(). Listeners can inspect and replace the generated URI. The parameters payload reflects the sanitized query arguments after handling of special parameters like id and _language.

The event offers the following methods:

  • getUri() and setUri()
  • getRoute()
  • getParameters()
  • getFragment()
  • getType()
  • getLanguage()
  • getSite()

When replacing the URI, listeners must ensure that the returned URI is valid in their setup and remains routable.

Example listener registration:

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Routing\Event\AfterPageUriGeneratedEvent;
use TYPO3\CMS\Core\Routing\RouterInterface;

#[AsEventListener('my-extension/after-page-uri-generated')]
final readonly class MyListener
{
    public function __invoke(AfterPageUriGeneratedEvent $event): void
    {
        // Only act on absolute URLs
        if ($event->getType() !== RouterInterface::ABSOLUTE_URL) {
            return;
        }
        // Inspect or replace $event->getUri()
    }
}
Copied!

Impact 

Extension authors can now react to generated page URIs for use cases like logging, monitoring, debugging or URL adjustment. Because the event is dispatched in all contexts that use PageRouter::generateUri(), including the backend and various subsystems, listeners should scope their modifications carefully.