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
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Redirects\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Redirects\Event\AfterAutoCreateRedirectHasBeenPersistedEvent;
use TYPO3\CMS\Redirects\RedirectUpdate\PlainSlugReplacementRedirectSource;
#[AsEventListener(
identifier: 'my-extension/after-auto-create-redirect-has-been-persisted',
)]
final readonly 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.
}
}
New in version 13.0
The PHP attribute \TYPO3\
has been
introduced to tag a PHP class as an event listener. Alternatively, or if you
need to be compatible with older TYPO3 versions, you can also register an
event listener via the Configuration/
file. Switch to
an older version of this page for an example or have a look at the section
Implementing an event listener in your extension.
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.