[BUGFIX] Linkvalidator validates linked content elements 12/57612/6
authorPatrick Broens <patrick@patrickbroens.nl>
Mon, 16 Jul 2018 13:49:45 +0000 (15:49 +0200)
committerBenni Mack <benni@typo3.org>
Sat, 27 Oct 2018 15:20:19 +0000 (17:20 +0200)
This patch makes the LinkValidator check typolinks to tt_content
elements like t3://page?uid=x#y by calling InternalLinktype twice, once
for the page as first part of the SoftReferenceIndex and again for the
tt_content element as second part.

Resolves: #85576
Related: #84016
Releases: master, 8.7
Change-Id: I94243e66f5eff38c9a0b0859a85aac48885e38ba
Reviewed-on: https://review.typo3.org/57612
Reviewed-by: Stephan Großberndt <stephan.grossberndt@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Sybille Peters <sypets@gmx.de>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/linkvalidator/Classes/Linktype/InternalLinktype.php

index ffd47db..4c1c80c 100644 (file)
@@ -73,7 +73,8 @@ class InternalLinktype extends AbstractLinktype
         unset($this->errorParams);
         // Only check pages records. Content elements will also be checked
         // as we extract the anchor in the next step.
-        if (strpos($softRefEntry['substr']['recordRef'], 'pages:') !== 0) {
+        [$table, $uid] = explode(':', $softRefEntry['substr']['recordRef']);
+        if (!in_array($table, ['pages', 'tt_content'], true)) {
             return true;
         }
         // Defines the linked page and anchor (if any).
@@ -81,6 +82,18 @@ class InternalLinktype extends AbstractLinktype
             $parts = explode('#c', $url);
             $page = $parts[0];
             $anchor = $parts[1];
+        } elseif (
+            $table === 'tt_content'
+            && strpos($softRefEntry['row'][$softRefEntry['field']], 't3://') === 0
+        ) {
+            $parsedTypoLinkUrl = @parse_url($softRefEntry['row'][$softRefEntry['field']]);
+            if ($parsedTypoLinkUrl['host'] === 'page') {
+                parse_str($parsedTypoLinkUrl['query'], $query);
+                if (isset($query['uid'])) {
+                    $page = (int)$query['uid'];
+                    $anchor = (int)$url;
+                }
+            }
         } else {
             $page = $url;
         }