RedirectIntegrityCheckEvent
New in version 14.2
The PSR-14 event
\TYPO3\
is dispatched for each redirect record during integrity checks, allowing
extensions to validate redirect targets (such as t3:// links) and flag broken or
invalid redirects. It is dispatched in
\TYPO3\
for each redirect record.
Additionally, the following class constants allow the
shared reuse of conflict statuses that extensions developers can set in custom
event listeners:
\TYPO3\,
\TYPO3\,
Extensions can now validate redirects during an integrity check by listening
to this event. Broken or invalid redirects are reported as well as
self-reference conflicts in the
redirects: command
output.
Example
An event listener that validates t3://record targets:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Redirects\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Redirects\Event\RedirectIntegrityCheckEvent;
use TYPO3\CMS\Redirects\Utility\RedirectConflict;
final readonly class MyEventListener
{
public function __construct(
private ConnectionPool $connectionPool,
) {}
#[AsEventListener('my-extension/validate-redirect-target')]
public function __invoke(RedirectIntegrityCheckEvent $event): void
{
$target = $event->getTarget();
if (!str_starts_with($target, 't3://record')) {
return;
}
// Parse t3://record?identifier=tx_news&uid=456
parse_str((string)parse_url($target, PHP_URL_QUERY), $params);
$table = $params['identifier'] ?? '';
$uid = (int)($params['uid'] ?? 0);
if ($table === '' || $uid === 0) {
$event->setIntegrityStatus(RedirectConflict::INVALID_TARGET);
return;
}
$count = $this->connectionPool
->getConnectionForTable($table)
->count('uid', $table, ['uid' => $uid]);
if ($count === 0) {
$event->setIntegrityStatus(RedirectConflict::INVALID_TARGET);
return;
}
// Set to NO_CONFLICT - will not be reported as conflicting redirect
// but will clear out already other integrity status.
$event->setIntegrityStatus(RedirectConflict::NO_CONFLICT);
}
}
API
- class RedirectIntegrityCheckEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Redirects\ Event\ Redirect Integrity Check Event
This event is fired in TYPO3CMSRedirectsServiceIntegrityService->checkRedirectTargetIntegrity() for each redirect record.
It can be used to perform custom validation on redirect targets and flag broken or invalid targets.
- getIntegrityStatus ( )
-
Be aware that this has been possible set by another earlier PSR-14 event listener already.
Could be any of the {@see RedirectConflict} constants, a custom value or
NULL. In case ofNULLno further handlinge are processed or regonized as conflict during the integrity checks.This is not initialized with the
sys_value.redirect. integirty_ status - Returns
-
?string