‪TYPO3CMS  11.5
FileInfoElement.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 
33 {
39  public function ‪render(): array
40  {
41  $resultArray = $this->‪initializeResultArray();
42 
43  $fileUid = 0;
44  if ($this->data['tableName'] === 'sys_file') {
45  $fileUid = (int)$this->data['databaseRow']['uid'];
46  } elseif ($this->data['tableName'] === 'sys_file_metadata') {
47  $fileUid = (int)($this->data['databaseRow']['file'][0] ?? 0);
48  }
49 
50  $fileObject = null;
51  if ($fileUid > 0) {
52  $fileObject = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
53  }
54  $resultArray['html'] = $this->‪renderFileInformationContent($fileObject);
55  return $resultArray;
56  }
57 
64  protected function ‪renderFileInformationContent(‪File $file = null): string
65  {
67  $lang = ‪$GLOBALS['LANG'];
68 
69  if ($file !== null) {
70  $content = '';
71  if ($file->isMissing()) {
72  $content .= '<span class="label label-danger label-space-right">'
73  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
74  . '</span>';
75  }
76  if ($file->isImage() || $file->isMediaFile()) {
77  $processedFile = $file->process(‪ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
78  $previewImage = $processedFile->getPublicUrl();
79  if ($previewImage) {
80  $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
81  'width="' . $processedFile->getProperty('width') . '" ' .
82  'height="' . $processedFile->getProperty('height') . '" ' .
83  'alt="" class="t3-tceforms-sysfile-imagepreview" />';
84  }
85  }
86  $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
87  $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize((int)$file->getSize())) . 'bytes)<br />';
88  $content .= BackendUtility::getProcessedValue('sys_file', 'type', (string)$file->getType()) . ' (' . $file->getMimeType() . ')<br />';
89  $content .= htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
90  $content .= '<a href="' . htmlspecialchars($file->getPublicUrl() ?? '') . '" target="_blank" title="' . $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.view') . '">' . htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '</a><br />';
91  $content .= '<br />';
92  } else {
93  $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>';
94  }
95 
96  return $content;
97  }
98 }
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGEPREVIEW
‪const CONTEXT_IMAGEPREVIEW
Definition: ProcessedFile.php:53
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:91
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement
Definition: FileInfoElement.php:33
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:35
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement\render
‪array render()
Definition: FileInfoElement.php:39
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:161
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:45
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement\renderFileInformationContent
‪string renderFileInformationContent(File $file=null)
Definition: FileInfoElement.php:64
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractFormElement.php:448
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50