From 38eb42dc5024c5863a4a53c104c8fc4dc8c206d5 Mon Sep 17 00:00:00 2001
From: Christian Weiske <weiske@mogic.com>
Date: Tue, 11 Jun 2024 09:29:28 +0200
Subject: [PATCH] [BUGFIX] Show element specific labels in linkvalidator report

The link validator "missing links" report shows the title of the
field which contains the missing link.

This title is loaded from `TCA.$table.columns.$field.label`,
but it is possible to use content-element specific labels in
`TCA.$table.types.$contenttype.columnsOverrides.*.label`,
and this is not supported by the validator.

The patch first tries to load the overridden label and
then falls back to the normal TCA column label.

This fixes titles of elements generated by the "mask" extension,
which only sets labels via overrides.

Resolves: #104035
Releases: main, 12.4
Change-Id: I1fa43a4cf0dbc910a8d2eea9b868aaf1cdbead0b
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84687
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Classes/Controller/LinkValidatorController.php   | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/typo3/sysext/linkvalidator/Classes/Controller/LinkValidatorController.php b/typo3/sysext/linkvalidator/Classes/Controller/LinkValidatorController.php
index 0a6f5ca93db8..bc0c6bc1e38b 100644
--- a/typo3/sysext/linkvalidator/Classes/Controller/LinkValidatorController.php
+++ b/typo3/sysext/linkvalidator/Classes/Controller/LinkValidatorController.php
@@ -371,12 +371,14 @@ class LinkValidatorController
         $hookObj = $this->linktypeRegistry->getLinktype($row['link_type'] ?? '');
 
         // Try to resolve the field label from TCA
-        if ($GLOBALS['TCA'][$table]['columns'][$row['field']]['label'] ?? false) {
+        if ($GLOBALS['TCA'][$table]['types'][$row['element_type']]['columnsOverrides'][$row['field']]['label'] ?? false) {
+            $fieldLabel = $languageService->sL($GLOBALS['TCA'][$table]['types'][$row['element_type']]['columnsOverrides'][$row['field']]['label']);
+        } elseif ($GLOBALS['TCA'][$table]['columns'][$row['field']]['label'] ?? false) {
             $fieldLabel = $languageService->sL($GLOBALS['TCA'][$table]['columns'][$row['field']]['label']);
-            // Crop colon from end if present
-            if (str_ends_with($fieldLabel, ':')) {
-                $fieldLabel = substr($fieldLabel, 0, -1);
-            }
+        }
+        // Crop colon from end if present
+        if (str_ends_with($fieldLabel, ':')) {
+            $fieldLabel = substr($fieldLabel, 0, -1);
         }
 
         return [
-- 
GitLab