AfterAutoCreateRedirectHasBeenPersistedEvent
New in version 12.3
The PSR-14 event
\TYPO3\
allows extensions to react on persisted auto-created redirects. This event
can be used to call external APIs or perform other tasks based on the real
persisted redirects.
Note
To handle later updates or react on manually created redirects in the backend
module, available hooks of \TYPO3\
can be used.
Example
Registration of the event listener in the extension's Services.
:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\Redirects\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/after-auto-create-redirect-has-been-persisted'
Read how to configure dependency injection in extensions.
The corresponding event listener class:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Redirects\EventListener;
use TYPO3\CMS\Redirects\Event\AfterAutoCreateRedirectHasBeenPersistedEvent;
use TYPO3\CMS\Redirects\RedirectUpdate\PlainSlugReplacementRedirectSource;
final class MyEventListener
{
public function __invoke(AfterAutoCreateRedirectHasBeenPersistedEvent $event): void
{
$redirectUid = $event->getRedirectRecord()['uid'] ?? null;
if ($redirectUid === null
&& !($event->getSource() instanceof PlainSlugReplacementRedirectSource)
) {
return;
}
// Implement code what should be done with this information. For example,
// write to another table, call a REST API or similar. Find your
// use case.
}
}
API
- class AfterAutoCreateRedirectHasBeenPersistedEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Redirects\ Event\ After Auto Create Redirect Has Been Persisted Event
This event is fired in the TYPO3CMSRedirectsServiceSlugService after a redirect record has been automatically created and persisted after page slug change. It's mainly a pure notification event.
It can be used to update redirects external in a load-balancer directly for example, or doing some kind of synchronization.