From c81403771fbe4ea7c9d52eb510cf03b50439d446 Mon Sep 17 00:00:00 2001 From: Anja Leichsenring <aleichsenring@ab-softlab.de> Date: Mon, 27 Feb 2017 15:00:18 +0100 Subject: [PATCH] [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: TYPO3com <no-reply@typo3.com> Reviewed-by: Josef Glatz <josef.glatz@typo3.org> Tested-by: Josef Glatz <josef.glatz@typo3.org> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Classes/Form/Element/FileInfoElement.php} | 55 +++++++++---------- .../backend/Classes/Form/NodeFactory.php | 1 + .../core/Configuration/TCA/sys_file.php | 2 +- .../Configuration/TCA/sys_file_metadata.php | 2 +- 4 files changed, 28 insertions(+), 32 deletions(-) rename typo3/sysext/{core/Classes/Resource/Hook/FileInfoHook.php => backend/Classes/Form/Element/FileInfoElement.php} (64%) diff --git a/typo3/sysext/core/Classes/Resource/Hook/FileInfoHook.php b/typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php similarity index 64% rename from typo3/sysext/core/Classes/Resource/Hook/FileInfoHook.php rename to typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php index 4a10f68df307..2a34f1a62263 100644 --- a/typo3/sysext/core/Classes/Resource/Hook/FileInfoHook.php +++ b/typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php @@ -1,5 +1,6 @@ <?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. @@ -22,41 +23,35 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; 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 string The HTML code for the TCEform field + * @return array As defined in initializeResultArray() of AbstractNode */ - public function renderFileInfo(array $propertyArray) + public function render(): array { - $fileRecord = $propertyArray['row']; - $fileObject = null; - if ($fileRecord['uid'] > 0) { - $fileObject = ResourceFactory::getInstance()->getFileObject((int)$fileRecord['uid']); + $resultArray = $this->initializeResultArray(); + + $fileUid = 0; + 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; - if (!empty($fileMetadataRecord['file']) && $fileMetadataRecord['file'][0] > 0) { - $fileObject = ResourceFactory::getInstance()->getFileObject((int)$fileMetadataRecord['file'][0]); + if ($fileUid > 0) { + $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid); } - - return $this->renderFileInformationContent($fileObject); + $resultArray['html'] = $this->renderFileInformationContent($fileObject); + return $resultArray; } /** @@ -65,7 +60,7 @@ class FileInfoHook * @param File $file * @return string */ - protected function renderFileInformationContent(File $file = null) + protected function renderFileInformationContent(File $file = null): string { /** @var LanguageService $lang */ $lang = $GLOBALS['LANG']; @@ -81,9 +76,9 @@ class FileInfoHook } if ($previewImage) { $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' . - 'width="' . $processedFile->getProperty('width') . '" ' . - 'height="' . $processedFile->getProperty('height') . '" ' . - 'alt="" class="t3-tceforms-sysfile-imagepreview" />'; + 'width="' . $processedFile->getProperty('width') . '" ' . + 'height="' . $processedFile->getProperty('height') . '" ' . + 'alt="" class="t3-tceforms-sysfile-imagepreview" />'; } $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>'; $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />'; diff --git a/typo3/sysext/backend/Classes/Form/NodeFactory.php b/typo3/sysext/backend/Classes/Form/NodeFactory.php index 45237340e5f4..9ba4098332de 100644 --- a/typo3/sysext/backend/Classes/Form/NodeFactory.php +++ b/typo3/sysext/backend/Classes/Form/NodeFactory.php @@ -90,6 +90,7 @@ class NodeFactory 'textTable' => Element\TextTableElement::class, 'unknown' => Element\UnknownElement::class, 'user' => Element\UserElement::class, + 'fileInfo' => Element\FileInfoElement::class, // Default classes to enrich single elements 'fieldControl' => NodeExpansion\FieldControl::class, diff --git a/typo3/sysext/core/Configuration/TCA/sys_file.php b/typo3/sysext/core/Configuration/TCA/sys_file.php index 0549b8e27a0b..b92b097b526b 100644 --- a/typo3/sysext/core/Configuration/TCA/sys_file.php +++ b/typo3/sysext/core/Configuration/TCA/sys_file.php @@ -30,7 +30,7 @@ return [ 'fileinfo' => [ 'config' => [ 'type' => 'user', - 'userFunc' => 'TYPO3\\CMS\\Core\\Resource\\Hook\\FileInfoHook->renderFileInfo' + 'renderType' => 'fileInfo', ] ], 'storage' => [ diff --git a/typo3/sysext/core/Configuration/TCA/sys_file_metadata.php b/typo3/sysext/core/Configuration/TCA/sys_file_metadata.php index 69a51c18a952..c98aa0b5306b 100644 --- a/typo3/sysext/core/Configuration/TCA/sys_file_metadata.php +++ b/typo3/sysext/core/Configuration/TCA/sys_file_metadata.php @@ -78,7 +78,7 @@ return [ 'fileinfo' => [ 'config' => [ 'type' => 'user', - 'userFunc' => 'TYPO3\\CMS\\Core\\Resource\\Hook\\FileInfoHook->renderFileMetadataInfo' + 'renderType' => 'fileInfo', ] ], 'file' => [ -- GitLab