#104387Linkvalidator shows wrong url for linked content
Description
When Linkvalidator finds a broken link to an content element the url has to be stored as [pageUid]#c[contentElementUid]. In case of bodytext this is the case and tested.
In case of header_link for example only the contentElementUid gets stored as url. The report then shows a link to a page with the uid of the content element which is wrong.
!clipboard-202407121743-zpghz.png!
First row shows the incorrect link, content element linked in header_link.
Second row shows the correct link, content element linked in bodytext.
As far as i can see, only fields with softref=typolink_tag handling links to content elements right.
TYPO3 12 and 13 are affected.
Reviews 3
Related issues 1
Files 2
History 1223
-
Ulrich Mathes changed description <span data-processor="relativetime" data-value="2024-07-12T15:51:55+00:00" > 07/12/24, 15:51 </span>
-
Ulrich Mathes changed description <span data-processor="relativetime" data-value="2024-07-12T15:56:00+00:00" > 07/12/24, 15:56 </span>
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2024-07-12T22:14:04+00:00" > 07/12/24, 22:14 </span>
-
Sybille Peters commented <span data-processor="relativetime" data-value="2024-07-15T12:35:06+00:00" > 07/15/24, 12:35 </span>
To summarize: The problem only occurs if a link to a content element is used in header_link, not in bodytext?
I can reproduce this.
I think I should be able to provide a patch. Here is some more information:
About debugging: you ideally debug LinkAnalyzer::analyzeRecord when checking links, e.g. by putting a breakpoint there with condition, e.g. $table == ‘tt_content’ or putting the breakpoint on line 337.
I also checked the database first because I wanted to make sure the problem is in the checking:
select url,table_name,field from tx_linkvalidator_link where record_pid=663; +-------------+------------+-------------+ | url | table_name | field | +-------------+------------+-------------+ | 101999 | tt_content | header_link | | 664#c101999 | tt_content | bodytext | +-------------+------------+-------------+
This confirms: It is already wrong when written to the DB, the URL should be the same.
The problem seems to be that for bodytext TypolinkTagSoftReferenceParser is used and for header_link TypolinkSoftReferenceParser. Both (correctly) return the same result, but in line 337 of LinkAnalyzer there is an if switch:
if ($softReferenceParser->getParserKey() === 'typolink_tag') { $this->analyzeTypoLinks($parserResult, $results, $htmlParser, $record, $field, $table); } else { $this->analyzeLinks($parserResult, $results, $record, $field, $table); }So for header_link analyzeLinks is called and for bodytext analyzeTypoLinks – even though it is also a typolink. Where in the one case pageAndAnchor is written and in the other not.
And you can see in line 214 what happens:
if (!empty($entryValue['pageAndAnchor'] ?? '')) { // Page with anchor, e.g. 18#1580 $url = $entryValue['pageAndAnchor']; } else { $url = $entryValue['substr']['tokenValue']; }I did not thoroughly debug that part, but pretty confident that is the problem.
This code has not been changed much for years. I will also check other versions 11 and 12 to check if new problem or already existed.
-
Sybille Peters commented <span data-processor="relativetime" data-value="2024-07-15T17:03:28+00:00" > 07/15/24, 17:03 </span>
I could also reproduce this in v11 and v12.
-
Ulrich Mathes commented <span data-processor="relativetime" data-value="2024-07-18T14:08:17+00:00" > 07/18/24, 14:08 </span>
We just came across this issue as we show broken links with an dashboard widget. The editors don’t usually use the backend module.
-
Sybille Peters changed Related to #104902 <span data-processor="relativetime" data-value="2024-09-11T15:39:39+00:00" > 09/11/24, 15:39 </span>
-
Sybille Peters commented and changed attached parserResult.png <span data-processor="relativetime" data-value="2024-10-29T12:09:11+00:00" > 10/29/24, 12:09 </span>
I think the problem is in the TypolinkSoftReferenceParser. This returns 2 results for the one link.
Is that correct behaviour? Should we change the behaviour in linkvalidator or in the parser?
for example: $parserResult = $softReferenceParser->parse(‘tt_content’, ‘header_link’, 700944, ‘t3://page?uid=108222#700943’);
-
Sybille Peters commented <span data-processor="relativetime" data-value="2024-10-29T15:13:43+00:00" > 10/29/24, 15:13 </span>
Please ignore my previous comment. It seems to be correct that the link parser returns 2 items for a link with anchor. (However the comment may still be useful for understanding the code).
I have fixed the behaviour in “brofix” which uses similar code see https://github.com/sypets/brofix/pull/404/files
Linkvalidator handles the results from TypolinkTagSoftreferenceParser and TypolinkSoftReferenceParser difference, for the former analyzeTypoLinks is called and for the latter analyzeLinks.
analyzeTypoLinks handles the duplicate entries for one link for the specific usecase page with anchor, analyzeLinks does not.
-
Gerrit Code Review pushed patch set 1 for main to change 86875 status
NewUnder Review <span data-processor="relativetime" data-value="2024-11-03T13:42:59+00:00" > 11/03/24, 13:42 </span> -
Gerrit Code Review pushed patch set 2 for main to change 86875 <span data-processor="relativetime" data-value="2024-11-03T13:43:43+00:00" > 11/03/24, 13:43 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 86875 <span data-processor="relativetime" data-value="2024-11-03T14:07:27+00:00" > 11/03/24, 14:07 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 86875 <span data-processor="relativetime" data-value="2024-11-03T14:09:41+00:00" > 11/03/24, 14:09 </span>
-
Gerrit Code Review pushed patch set 5 for main to change 86875 <span data-processor="relativetime" data-value="2024-11-05T07:08:49+00:00" > 11/05/24, 07:08 </span>
-
Gerrit Code Review pushed patch set 6 for main to change 86875 <span data-processor="relativetime" data-value="2024-11-05T08:11:19+00:00" > 11/05/24, 08:11 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 87004 <span data-processor="relativetime" data-value="2024-11-16T15:59:21+00:00" > 11/16/24, 15:59 </span>
-
Sybille Peters changed status
Under ReviewNew <span data-processor="relativetime" data-value="2024-12-30T10:48:03+00:00" > 12/30/24, 10:48 </span> -
Sybille Peters commented <span data-processor="relativetime" data-value="2024-12-30T10:48:15+00:00" > 12/30/24, 10:48 </span>
patch was abandoned.
-
Gerrit Code Review pushed patch set 2 for main to change 87004 status
NewUnder Review <span data-processor="relativetime" data-value="2026-09-23T14:49:20+00:00" > 09/23/26, 14:49 </span> -
Gerrit Code Review pushed patch set 3 for main to change 87004 <span data-processor="relativetime" data-value="2026-09-23T15:16:14+00:00" > 09/23/26, 15:16 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 87004 <span data-processor="relativetime" data-value="2026-09-23T15:16:29+00:00" > 09/23/26, 15:16 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 96003 <span data-processor="relativetime" data-value="2026-09-23T16:13:22+00:00" > 09/23/26, 16:13 </span>
-
Sybille Peters commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-09-23T16:15:12+00:00" > 09/23/26, 16:15 </span>Applied in changeset commit:880fdbd065df533a3eeaf9ca45076b2cd27cbe40.
Reproduced this via:
1. Create a page “Invisible“
2. Create a content element of type “Header Only”. Can be empty.
3. Hide that content element.
4. Create a page “Linked”.
5. Create a content element of type “Header Only”. For the field “Link [header_link]” open the link browser, go to page “Invisible”, select hidden content element there.
6. Go to linkvalidator, validate the page “Linked“
7. The resulting output will show the error from the screenshot, the broken link will lead to having the page UID set as the content element UID
I’ve tried to debug this for more than an hour, and the code is very hard for me to read.
https://github.com/TYPO3/typo3/blob/main/typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php#L370seems to be missing an array key likebut I can’t see how to construct this to only do that in case of a “t3://page?uid=4711#0815” link.
In
https://github.com/TYPO3/typo3/blob/main/typo3/sysext/linkvalidator/Classes/Linktype/InternalLinktype.php#L95there’s already some ‘t3://’ parsing involved, unsure if there a specific key needs to be set.Ultimately, in
https://github.com/TYPO3/typo3/blob/main/typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php#L211there’s:if (!empty($entryValue['pageAndAnchor'] ?? '')) { // Page with anchor, e.g. 18#1580 $url = $entryValue['pageAndAnchor']; } else { $url = $entryValue['substr']['tokenValue']; }where the proper URL would need to be referenced. As noted this “pageAndAnchor” would be a key that could be utilized. Otherwize the `$url` variable here could also be set to something from `$entryValue` but I don’t really get where all this is coming from and to.
Jsut leaving this here in case it finds someone with expertise or more willpower than me.