Skip to content
Snippets Groups Projects
Commit c8140377 authored by Anja Leichsenring's avatar Anja Leichsenring Committed by Christian Kuhn
Browse files

[TASK] Replace FileInfoHook with renderType

Switch a userFunc to a proper renderType used in fileinfo field
of sys_file and sys_file_metadata table.

Resolves: #80039
Releases: master
Change-Id: I7093027716cb43fa2f00044f51d918cc8f91ee6e
Reviewed-on: https://review.typo3.org/51874


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarJosef Glatz <josef.glatz@typo3.org>
Tested-by: default avatarJosef Glatz <josef.glatz@typo3.org>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 165f392a
No related merge requests found
<?php <?php
namespace TYPO3\CMS\Core\Resource\Hook; declare(strict_types=1);
namespace TYPO3\CMS\Backend\Form\Element;
/* /*
* This file is part of the TYPO3 CMS project. * This file is part of the TYPO3 CMS project.
...@@ -22,41 +23,35 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; ...@@ -22,41 +23,35 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Lang\LanguageService; use TYPO3\CMS\Lang\LanguageService;
/** /**
* Utility class to render TCEforms information about a sys_file record * This renderType is used with type=user in FAL for table sys_file and
* sys_file_metadata, for field fileinfo and renders an informational
* element with image preview, filename, size and similar.
*/ */
class FileInfoHook class FileInfoElement extends AbstractFormElement
{ {
/** /**
* User function for sys_file (element) * Handler for single nodes
* *
* @param array $propertyArray the array with additional configuration options. * @return array As defined in initializeResultArray() of AbstractNode
* @return string The HTML code for the TCEform field
*/ */
public function renderFileInfo(array $propertyArray) public function render(): array
{ {
$fileRecord = $propertyArray['row']; $resultArray = $this->initializeResultArray();
$fileObject = null;
if ($fileRecord['uid'] > 0) { $fileUid = 0;
$fileObject = ResourceFactory::getInstance()->getFileObject((int)$fileRecord['uid']); if ($this->data['tableName'] === 'sys_file') {
$fileUid = (int)$this->data['databaseRow']['uid'];
} elseif ($this->data['tableName'] === 'sys_file_metadata') {
$fileUid = (int)$this->data['databaseRow']['file'][0];
} }
return $this->renderFileInformationContent($fileObject);
}
/**
* User function for sys_file_meta (element)
*
* @param array $propertyArray the array with additional configuration options.
* @return string The HTML code for the TCEform field
*/
public function renderFileMetadataInfo(array $propertyArray)
{
$fileMetadataRecord = $propertyArray['row'];
$fileObject = null; $fileObject = null;
if (!empty($fileMetadataRecord['file']) && $fileMetadataRecord['file'][0] > 0) { if ($fileUid > 0) {
$fileObject = ResourceFactory::getInstance()->getFileObject((int)$fileMetadataRecord['file'][0]); $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
} }
$resultArray['html'] = $this->renderFileInformationContent($fileObject);
return $this->renderFileInformationContent($fileObject); return $resultArray;
} }
/** /**
...@@ -65,7 +60,7 @@ class FileInfoHook ...@@ -65,7 +60,7 @@ class FileInfoHook
* @param File $file * @param File $file
* @return string * @return string
*/ */
protected function renderFileInformationContent(File $file = null) protected function renderFileInformationContent(File $file = null): string
{ {
/** @var LanguageService $lang */ /** @var LanguageService $lang */
$lang = $GLOBALS['LANG']; $lang = $GLOBALS['LANG'];
...@@ -81,9 +76,9 @@ class FileInfoHook ...@@ -81,9 +76,9 @@ class FileInfoHook
} }
if ($previewImage) { if ($previewImage) {
$content .= '<img src="' . htmlspecialchars($previewImage) . '" ' . $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
'width="' . $processedFile->getProperty('width') . '" ' . 'width="' . $processedFile->getProperty('width') . '" ' .
'height="' . $processedFile->getProperty('height') . '" ' . 'height="' . $processedFile->getProperty('height') . '" ' .
'alt="" class="t3-tceforms-sysfile-imagepreview" />'; 'alt="" class="t3-tceforms-sysfile-imagepreview" />';
} }
$content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>'; $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
$content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />'; $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />';
......
...@@ -90,6 +90,7 @@ class NodeFactory ...@@ -90,6 +90,7 @@ class NodeFactory
'textTable' => Element\TextTableElement::class, 'textTable' => Element\TextTableElement::class,
'unknown' => Element\UnknownElement::class, 'unknown' => Element\UnknownElement::class,
'user' => Element\UserElement::class, 'user' => Element\UserElement::class,
'fileInfo' => Element\FileInfoElement::class,
// Default classes to enrich single elements // Default classes to enrich single elements
'fieldControl' => NodeExpansion\FieldControl::class, 'fieldControl' => NodeExpansion\FieldControl::class,
......
...@@ -30,7 +30,7 @@ return [ ...@@ -30,7 +30,7 @@ return [
'fileinfo' => [ 'fileinfo' => [
'config' => [ 'config' => [
'type' => 'user', 'type' => 'user',
'userFunc' => 'TYPO3\\CMS\\Core\\Resource\\Hook\\FileInfoHook->renderFileInfo' 'renderType' => 'fileInfo',
] ]
], ],
'storage' => [ 'storage' => [
......
...@@ -78,7 +78,7 @@ return [ ...@@ -78,7 +78,7 @@ return [
'fileinfo' => [ 'fileinfo' => [
'config' => [ 'config' => [
'type' => 'user', 'type' => 'user',
'userFunc' => 'TYPO3\\CMS\\Core\\Resource\\Hook\\FileInfoHook->renderFileMetadataInfo' 'renderType' => 'fileInfo',
] ]
], ],
'file' => [ 'file' => [
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment