Feature: #29342 - Improve ValidatorTask
See forge#29342
Description
The
\TYPO3\ scheduler task for
reporting broken links via email which still used marker templates, has been
improved. This is achieved by switching to Fluid, extending the task
configuration along with the mails content for more detailed reports, code
refactoring and introduction of strict types for both
\TYPO3\ and
\TYPO3\.
The task configuration got the following new fields:
languagesComma separated list of language uidsemailName of the fluid templateTemplate Name
With languages it's now possible to limit the report to specified system
languages. This is useful if multiple tasks for different groups of recipients
should be registered.
With email it is possible to use different custom templates for each
task. The template path must be set in
$GLOBALS. Additionally
the used System layout can be changed by setting your custom layout
path in
$GLOBALS. If no
email is set or the specified input is invalid, the task
automatically uses the default template name on task execution.
The following new PSR-14 event has been introduced:
\TYPO3\
This event can be used to manipulate the
\TYPO3\,
which contains all information from the linkvalidator API. Also the Fluid
object can be adjusted here. This allows to e.g. pass additional information to
the view by using
$fluid or dynamically adding mail information
such as the receivers list. The added values in the event take precedence over the
mod configuration. The event contains the full
mod
to access further information about the actual configuration of the task when
assigning new values to Fluid.
Note: As it's now also possible to set the recipient addresses dynamically using
the event, the email field in the task configuration can remain empty but will
be added, if defined, on top of already defined recipients from the event. All
other values such as subject, from or reply will only be set according to
mod if not already defined through the event.
An example implementation of the PSR-14 event:
<?php
declare(strict_types=1);
namespace Vendor\Extension\EventListener;
use TYPO3\CMS\Linkvalidator\Event\ModifyValidatorTaskEmailEvent;
class ModifyValidatorTaskEmail
{
public function modify(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'));
}
}
Vendor\Extension\EventListener\ModifyValidatorTaskEmail:
tags:
- name: event.listener
identifier: 'modify-validation-task-email'
event: TYPO3\CMS\Linkvalidator\Event\ModifyValidatorTaskEmailEvent
method: 'modify'
The
\TYPO3\ contains following
information by default:
$oldAmount of broken links from the last run, separated by type (e.g. all, internal)Broken Link Counts $newAmount of broken links from this run, separated by type (e.g. all, internal)Broken Link Counts $brokenList of broken links with the raw database rowLinks $differentWhether the broken links count changedTo Last Result
The
broken property gets further processed internally to provide additional
information for the email. Following additional information is provided by default:
full_The full record, the broken link was found in (e.g. pages or tt_content)record record_Value of thetitle full_title fieldrecord record_The title of the record type (e.g. "Page" or "Page Content")type language_The language code of the broken linkcode real_The real page id of the record the broken link was found inpid page_The whole page row of records parent pagerecord
More can be added using the 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:
RecordTherecord_anduid record_title LanguageThelanguage_and language idcode PageThereal_andpid page_of the parent pagerecord. title Record TypeTherecord_type Link TargetThetargetLink TypeType of the broken link (Eitherinternal,externalorfile)
Impact
The main improvement is the more detailed report which is delivered by Fluid,
using the default System layout. Along with the new PSR-14 event, extension authors
are now able to fully customize the content of the report as needed.