AfterAutoCreateRedirectHasBeenPersistedEvent

New in version 12.3

The PSR-14 event \TYPO3\CMS\Redirects\Event\AfterAutoCreateRedirectHasBeenPersistedEvent 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.

Example

EXT:my_extension/Classes/Redirects/EventListener/MyEventListener.php
<?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.
    }
}
Copied!

New in version 13.0

API

class AfterAutoCreateRedirectHasBeenPersistedEvent
Fully qualified name
\TYPO3\CMS\Redirects\Event\AfterAutoCreateRedirectHasBeenPersistedEvent

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.

getSlugRedirectChangeItem ( )
Returns
\TYPO3\CMS\Redirects\RedirectUpdate\SlugRedirectChangeItem
getSource ( )
Returns
\TYPO3\CMS\Redirects\RedirectUpdate\RedirectSourceInterface
getRedirectRecord ( )
Returns
array