[FEATURE] Improve usability for BE database thumbnails/file icons 56/20456/5
authorPatrick Broens <patrick@patrickbroens.nl>
Sat, 12 Oct 2013 22:20:18 +0000 (00:20 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 13 Oct 2013 00:50:05 +0000 (02:50 +0200)
The backend produces thumbnails/file icons/truetype font previews which
come from a database row. The usability for these images can be improved
by showing the file name or title on hover using the title attribute.
Currently only the thumbnail/icon is produced and more information can
only be read by clicking the icon or opening the record, like in the
content element File Links.

This patch changes the alt attribute to the alternative text and adds the
title attribute for these images. When no title has been given for a file
record, the file name will be used instead.

Change-Id: I23b761fb204dda2c200f3ea57961cc017840fcac
Fixes: #47709
Releases: 6.2
Reviewed-on: https://review.typo3.org/20456
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index bc14e4b..38bcb57 100644 (file)
@@ -1540,6 +1540,11 @@ class BackendUtility {
                        foreach ($referenceUids as $referenceUid) {
                                $fileReferenceObject = ResourceFactory::getInstance()->getFileReferenceObject($referenceUid['uid']);
                                $fileObject = $fileReferenceObject->getOriginalFile();
+                               $fileAlternative = $fileReferenceObject->getAlternative();
+                               $fileTitle = $fileReferenceObject->getTitle();
+                               if ($fileTitle === '') {
+                                       $fileTitle = $fileReferenceObject->getName();
+                               }
 
                                if ($fileObject->isMissing()) {
                                        $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
@@ -1553,10 +1558,16 @@ class BackendUtility {
                                                'width' => $sizeParts[0],
                                                'height' => $sizeParts[1]
                                        ))->getPublicUrl(TRUE);
-                                       $imgTag = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($fileReferenceObject->getName()) . '" />';
+                                       $imgTag = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($fileAlternative) . '" title="' . htmlspecialchars($fileTitle) . '" />';
                                } else {
                                        // Icon
-                                       $imgTag = IconUtility::getSpriteIconForFile(strtolower($fileObject->getExtension()), array('title' => $fileObject->getName()));
+                                       $imgTag = IconUtility::getSpriteIconForFile(
+                                               strtolower($fileObject->getExtension()),
+                                               array(
+                                                       'title' => $fileTitle,
+                                                       'alt'=> $fileAlternative
+                                               )
+                                       );
                                }
                                if ($linkInfoPopup) {
                                        $onClick = 'top.launchView(\'_FILE\',\'' . $fileObject->getUid() . '\',\'' . $backPath . '\'); return false;';
@@ -1579,6 +1590,11 @@ class BackendUtility {
                                        $fileName = trim($uploaddir . '/' . $theFile, '/');
                                        $fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileName);
                                        $fileExtension = $fileObject->getExtension();
+                                       $fileAlternative = $fileObject->getAlternative();
+                                       $fileTitle = $fileObject->getTitle();
+                                       if ($fileTitle === '') {
+                                               $fileTitle = $fileObject->getName();
+                                       }
 
                                        if ($fileObject->isMissing()) {
                                                $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
@@ -1591,7 +1607,7 @@ class BackendUtility {
                                                        'width' => $sizeParts[0],
                                                        'height' => $sizeParts[1]
                                                ))->getPublicUrl(TRUE);
-                                               $image = '<img src="' . htmlspecialchars($imageUrl) . '" hspace="2" border="0" title="' . htmlspecialchars($fileObject->getName()) . '"' . $tparams . ' alt="" />';
+                                               $image = '<img src="' . htmlspecialchars($imageUrl) . '" hspace="2" border="0" title="' . htmlspecialchars($fileTitle) . '"' . $tparams . ' alt="' . htmlspecialchars($fileAlternative) . '" />';
                                                if ($linkInfoPopup) {
                                                        $onClick = 'top.launchView(\'_FILE\', \'' . $fileName . '\',\'\',\'' . $backPath . '\');return false;';
                                                        $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $image . '</a> ';
@@ -1600,7 +1616,13 @@ class BackendUtility {
                                                }
                                        } else {
                                                // Gets the icon
-                                               $fileIcon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName()));
+                                               $fileIcon = IconUtility::getSpriteIconForFile(
+                                                       $fileExtension,
+                                                       array(
+                                                               'title' => $fileTitle,
+                                                               'alt' => $fileAlternative
+                                                       )
+                                               );
                                                if ($linkInfoPopup) {
                                                        $onClick = 'top.launchView(\'_FILE\', \'' . $fileName . '\',\'\',\'' . $backPath . '\'); return false;';
                                                        $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $fileIcon . '</a> ';