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

Registration of the event listener in the extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
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'
Copied!

Read how to configure dependency injection in extensions.

The corresponding event listener class:

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

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