Commit 27859172 authored by Sybille Peters's avatar Sybille Peters 🙋 Committed by Benni Mack
Browse files

[BUGFIX] Mark broken links to hidden page and CEs

Broken links are marked in RTE by using the attribute
data-rte-error in the <a> tag, which results in a
special style and lets the link be visible as broken.

Previously this was not done for links to hidden pages
and links to content elements. These links were however
detected as broken by linkvalidator and displayed in
the list of broken links. Marking them in RTE as well
makes the behaviour consistent.

This patch ensures the consistency between the list
and the visual highlighting in RTE elements for links
to hidden pages and hidden content elements.

Highlighting links to hidden pages/content elements
on hidden pages may be visually relaxed to a notice
instead of an error in a dedicated patch as feature.

One PHP8.0 array key warning is fixed along the way.

Resolves: #93005
Releases: main, 11.5
Change-Id: Ib1ef4b81ab862657950a38e5ee6847dd82abb13f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67039


Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 90c2181b
......@@ -47,7 +47,7 @@ final class CheckBrokenRteLinkEventListener
}
$url = (string)($event->getLinkData()['url'] ?? '');
if (!empty($url)) {
if ($this->brokenLinkRepository->isLinkTargetBrokenLink($url)) {
if ($this->brokenLinkRepository->isLinkTargetBrokenLink($url, 'external')) {
$event->markAsBrokenLink('External link is broken');
}
}
......@@ -65,10 +65,25 @@ final class CheckBrokenRteLinkEventListener
if ($pageUid === '' || $pageUid === 'current') {
return;
}
$pageRecord = BackendUtility::getRecord('pages', $hrefInformation['pageuid']);
// pageUid should be int at this point
$pageUid = (int)$pageUid;
$pageRecord = BackendUtility::getRecord('pages', $pageUid);
// Page does not exist
if (!is_array($pageRecord)) {
$event->markAsBrokenLink('Page with ID ' . htmlspecialchars($hrefInformation['pageuid']) . ' not found');
$event->markAsBrokenLink('Page with ID ' . $pageUid . ' not found');
return;
}
if (($pageRecord['hidden'] ?? 0) === 1) {
$event->markAsBrokenLink('Page with ID ' . $pageUid . ' is hidden');
} else {
$fragment = $hrefInformation['fragment'] ?? '';
if ($fragment !== '') {
$url = $hrefInformation['pageuid'] . '#c' . $fragment;
if ($this->brokenLinkRepository->isLinkTargetBrokenLink($url, 'db')) {
$event->markAsBrokenLink('Page with ID ' . $pageUid
. ' exists, but fragment ' . htmlspecialchars($fragment) . ' does not');
}
}
}
}
......@@ -91,7 +106,7 @@ final class CheckBrokenRteLinkEventListener
return;
}
if ($this->brokenLinkRepository->isLinkTargetBrokenLink('file:' . $file->getProperty('uid'))) {
if ($this->brokenLinkRepository->isLinkTargetBrokenLink('file:' . $file->getProperty('uid'), 'file')) {
$event->markAsBrokenLink('File with ID ' . $file->getProperty('uid') . ' not found');
}
}
......
......@@ -233,7 +233,7 @@ class InternalLinktype extends AbstractLinktype
$errorContent = null;
$lang = $this->getLanguageService();
$errorType = $errorParams['errorType'];
if (is_array($errorParams['page'])) {
if (is_array($errorParams['page'] ?? false)) {
switch ($errorType['page']) {
case self::DELETED:
$errorPage = str_replace(
......
......@@ -37,17 +37,23 @@ class BrokenLinkRepository
* a page uid (for db links), a file reference (for file links), etc.
* @return bool is the link target a broken link
*/
public function isLinkTargetBrokenLink(string $linkTarget): bool
public function isLinkTargetBrokenLink(string $linkTarget, string $linkType = ''): bool
{
try {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable(static::TABLE);
$constraints = [
$queryBuilder->expr()->eq('url', $queryBuilder->createNamedParameter($linkTarget)),
];
if ($linkType !== '') {
$constraints[] = $queryBuilder->expr()->eq('link_type', $queryBuilder->createNamedParameter($linkType));
}
$queryBuilder
->count('uid')
->from(static::TABLE)
->where(
$queryBuilder->expr()->eq('url', $queryBuilder->createNamedParameter($linkTarget))
);
->where(...$constraints);
return (bool)$queryBuilder
->execute()
->fetchOne();
......
Supports Markdown
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