Skip to content
Snippets Groups Projects
Commit 7378035e authored by Sybille Peters's avatar Sybille Peters Committed by Susanne Moog
Browse files

[FEATURE] Mark broken file links in RTE

Broken file links are now marked in RTE with yellow background and red
border.

This patch uses the previously introduced event
:php:`BrokenLinkAnalysisEvent`.

The broken links are only detected if linkvalidator is installed and
has checked for broken links (e.g. via scheduler).

Resolves: #84990
Releases: master
Change-Id: Iddebe7f9358901c70f90f9751298ce2905684662
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62091


Tested-by: default avatarDaniel Goerz <daniel.goerz@posteo.de>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarSybille Peters <sypets@gmx.de>
Tested-by: default avatarRiccardo De Contardi <erredeco@gmail.com>
Tested-by: default avatarSusanne Moog <look@susi.dev>
Reviewed-by: default avatarSybille Peters <sypets@gmx.de>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: default avatarSusanne Moog <look@susi.dev>
parent 3669742d
Branches
Tags
No related merge requests found
.. include:: ../../Includes.txt
===============================================
Feature: #84990 - Mark broken file links in RTE
===============================================
See :issue:`84990`
Description
===========
Links to files that were detected as broken by the system extension
`linkvalidator` are now marked accordingly in the RTE via
:php:`TYPO3\CMS\Core\Html\Event\BrokenLinkAnalysisEvent`.
Those links are now marked with extra markup (yellow background with
red border) in RTE.
The procedure for marking the broken links in the RTE is as follow:
#. RTE content is fetched from the database. Before it is displayed in
the edit form, RTE transformations are performed.
#. The transformation function parses the text and detects links.
#. For each link, a new PSR-14 event is dispatched.
#. If a listener is attached, it may set the link as broken and will set
the link as "checked".
#. If a link is detected as broken, RTE will mark it as broken.
The implementation for checking file links is supplied by the system
extension `linkvalidator`.
Other extensions can use the event to override the default behaviour.
Impact
======
The behaviour stays the same as before unless the system extension `linkvalidator`
is installed.
If `linkvalidator` is installed and regularly checks for broken file links, those
links will be marked in the RTE.
If `linkvalidator` is used, it is recommended to use the scheduler to regularly
check for broken links.
.. index:: RTE, ext:linkvalidator
......@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Linkvalidator\EventListener;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Html\Event\BrokenLinkAnalysisEvent;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Linkvalidator\Repository\BrokenLinkRepository;
/**
......@@ -67,4 +68,29 @@ final class CheckBrokenRteLinkEventListener
}
$event->markAsCheckedLink();
}
public function checkFileLink(BrokenLinkAnalysisEvent $event): void
{
if ($event->getLinkType() !== LinkService::TYPE_FILE) {
return;
}
$event->markAsCheckedLink();
$hrefInformation = $event->getLinkData();
$file = $hrefInformation['file'] ?? null;
if (!$file instanceof FileInterface) {
$event->markAsBrokenLink('File link is broken');
return;
}
if (!$file->hasProperty('uid') || (int)$file->getProperty('uid') === 0) {
$event->markAsBrokenLink('File link is broken');
return;
}
$count = $this->brokenLinkRepository->getNumberOfBrokenLinks('file:' . $file->getProperty('uid'));
if ($count) {
$event->markAsBrokenLink('File with ID ' . $file->getProperty('uid') . ' not found');
}
}
}
......@@ -20,3 +20,7 @@ services:
identifier: 'rte-check-link-to-page',
event: TYPO3\CMS\Core\Html\Event\BrokenLinkAnalysisEvent,
method: 'checkPageLink' }
- { name: event.listener,
identifier: 'rte-check-link-to-file',
event: TYPO3\CMS\Core\Html\Event\BrokenLinkAnalysisEvent,
method: 'checkFileLink' }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment