ModifyValidatorTaskEmailEvent

The PSR-14 event \TYPO3\CMS\Linkvalidator\Event\ModifyValidatorTaskEmailEvent can be used to manipulate the \TYPO3\CMS\Linkvalidator\Result\LinkAnalyzerResult, which contains all information from the linkvalidator API. Also the FluidEmail object can be adjusted there. This allows to pass additional information to the view by using $fluidEmail->assign() or dynamically adding mail information such as the receivers list. The added values in the event take precedence over the modTSconfig configuration. The event contains the full modTSconfig to access further information about the actual configuration of the task when assigning new values to FluidEmail.

Example

EXT:my_extension/Classes/Linkvalidator/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Linkvalidator\EventListener;

use Symfony\Component\Mime\Address;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Linkvalidator\Event\ModifyValidatorTaskEmailEvent;

#[AsEventListener(
    identifier: 'my-extension/modify-validation-task-email',
)]
final readonly class MyEventListener
{
    public function __invoke(ModifyValidatorTaskEmailEvent $event): void
    {
        $linkAnalyzerResult = $event->getLinkAnalyzerResult();
        $fluidEmail = $event->getFluidEmail();
        $modTSconfig = $event->getModTSconfig();

        if ($modTSconfig['mail.']['fromname'] === 'John Smith') {
            $fluidEmail->assign('myAdditionalVariable', 'foobar');
        }

        $fluidEmail->subject(
            $linkAnalyzerResult->getTotalBrokenLinksCount() . ' new broken links',
        );

        $fluidEmail->to(new Address('custom@mail.com'));
    }
}
Copied!

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener 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/Services.yaml 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.

The \TYPO3\CMS\Linkvalidator\Result\LinkAnalyzerResult contains the following information by default:

$oldBrokenLinkCounts
Amount of broken links from the last run, separated by type (for example: all, internal)
$newBrokenLinkCounts
Amount of broken links from this run, separated by type (for example: all, internal)
$brokenLinks
List of broken links with the raw database row
$differentToLastResult
Whether the broken links count changed

The brokenLinks property gets further processed internally to provide additional information for the email. Following additional information is provided by default:

full_record
The full record, the broken link was found in (for example: pages or tt_content)
record_title
Value of the full_record title field
record_type
The title of the record type (for example: "Page" or "Page Content")
language_code
The language code of the broken link
real_pid
The real page ID of the record the broken link was found in
page_record
The whole page row of records parent page

More can be added using this PSR-14 event.

Additionally to the already existing content, the email now includes a list of all broken links fetched according to the task configuration. This list consists of following columns:

Record
The record_uid and record_title
Language
The language_code and language ID
Page
The real_pid and page_record.title of the parent page
Record Type
The record_type
Link Target
The target
Link Type
Type of the broken link (either internal, external or file)

API

class \TYPO3\CMS\Linkvalidator\Event\ ModifyValidatorTaskEmailEvent

Allows to process and modify the LinkAnalyzer result and FluidEmail object

getLinkAnalyzerResult ( )
returntype

TYPO3\CMS\Linkvalidator\Result\LinkAnalyzerResult

getFluidEmail ( )
returntype

TYPO3\CMS\Core\Mail\FluidEmail

getModTSconfig ( )
returntype

array