From ee5a12c0b733b04b9f8d0758df7fd6dac44c38c3 Mon Sep 17 00:00:00 2001
From: Willi Wehmeier <wwwehmeier@gmail.com>
Date: Wed, 22 Nov 2023 15:13:58 +0100
Subject: [PATCH] [TASK] Add pagetitle to tooltip on page icon in treeview

To deliver a meaningful tooltip text for screenreaders the
title of the page is added to the tooltip message in the pagetree view.

Resolves: #102451
Releases: main, 12.4
Change-Id: I8af2e3652d38abb6b2a090c2f8bd0e4427ab255a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81854
Reviewed-by: Benjamin Kott <benjamin.kott@outlook.com>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Benjamin Kott <benjamin.kott@outlook.com>
---
 .../backend/Classes/Controller/Page/TreeController.php |  2 +-
 .../sysext/backend/Classes/Utility/BackendUtility.php  | 10 ++++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Controller/Page/TreeController.php b/typo3/sysext/backend/Classes/Controller/Page/TreeController.php
index be5f5719b484..d89adb815db0 100644
--- a/typo3/sysext/backend/Classes/Controller/Page/TreeController.php
+++ b/typo3/sysext/backend/Classes/Controller/Page/TreeController.php
@@ -358,7 +358,7 @@ class TreeController
         $prefix = '';
         $nameSourceField = 'title';
         $visibleText = $page['title'];
-        $tooltip = BackendUtility::titleAttribForPages($page, '', false);
+        $tooltip = BackendUtility::titleAttribForPages($page, '', false, $this->useNavTitle);
         if ($pageId !== 0) {
             $icon = $this->iconFactory->getIconForRecord('pages', $page, IconSize::SMALL);
         } else {
diff --git a/typo3/sysext/backend/Classes/Utility/BackendUtility.php b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
index df062a089e1a..f6989de8c48e 100644
--- a/typo3/sysext/backend/Classes/Utility/BackendUtility.php
+++ b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
@@ -1124,9 +1124,10 @@ class BackendUtility
      * @param array $row Input must be a page row ($row) with the proper fields set (be sure - send the full range of fields for the table)
      * @param string $perms_clause This is used to get the record path of the shortcut page, if any (and doktype==4)
      * @param bool $includeAttrib If $includeAttrib is set, then the 'title=""' attribute is wrapped about the return value, which is in any case htmlspecialchar()'ed already
+     * @param bool $preferNavTitle Prefers the 'nav_title' if available over the 'title' (nessesary for Tree with options.pageTree.showNavTitle = 1)
      * @return string
      */
-    public static function titleAttribForPages($row, $perms_clause = '', $includeAttrib = true)
+    public static function titleAttribForPages($row, $perms_clause = '', $includeAttrib = true, $preferNavTitle = false)
     {
         if (!isset($row['uid'])) {
             return '';
@@ -1134,8 +1135,13 @@ class BackendUtility
         $lang = static::getLanguageService();
         $parts = [];
         $parts[] = 'id=' . $row['uid'];
+        if ($preferNavTitle && trim($row['nav_title'] ?? '') !== '') {
+            $parts[] = $row['nav_title'];
+        } else {
+            $parts[] = $row['title'];
+        }
         if ($row['uid'] === 0) {
-            $out = htmlspecialchars($parts[0]);
+            $out = htmlspecialchars(implode(' - ', $parts));
             return $includeAttrib ? 'title="' . $out . '"' : $out;
         }
         switch (VersionState::tryFrom($row['t3ver_state'] ?? 0)) {
-- 
GitLab