‪TYPO3CMS  ‪main
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;
25 
32 {
33  public function ‪__construct(
34  private readonly ‪ResourceFactory $resourceFactory,
35  ) {}
36 
42  public function ‪render(): array
43  {
44  $resultArray = $this->‪initializeResultArray();
45 
46  $fileUid = 0;
47  if ($this->data['tableName'] === 'sys_file') {
48  $fileUid = (int)$this->data['databaseRow']['uid'];
49  } elseif ($this->data['tableName'] === 'sys_file_metadata') {
50  $fileUid = (int)($this->data['databaseRow']['file'][0] ?? 0);
51  }
52 
53  $fileObject = null;
54  if ($fileUid > 0) {
55  $fileObject = $this->resourceFactory->getFileObject($fileUid);
56  }
57  $resultArray['html'] = $this->‪renderFileInformationContent($fileObject);
58  return $resultArray;
59  }
60 
64  protected function ‪renderFileInformationContent(‪File $file = null): string
65  {
66  $lang = $this->‪getLanguageService();
67 
68  if ($file !== null) {
69  $content = '';
70  if ($file->isMissing()) {
71  $content .= '<span class="badge badge-danger badge-space-end">'
72  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
73  . '</span>';
74  }
75  if ($file->isImage() || $file->isMediaFile()) {
76  $processedFile = $file->process(‪ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
77  $previewImage = $processedFile->getPublicUrl();
78  if ($previewImage) {
79  $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
80  'width="' . $processedFile->getProperty('width') . '" ' .
81  'height="' . $processedFile->getProperty('height') . '" ' .
82  'alt="" class="t3-tceforms-sysfile-imagepreview" />';
83  }
84  }
85  $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
86  $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize((int)$file->getSize())) . 'bytes)<br />';
87  $content .= BackendUtility::getProcessedValue('sys_file', 'type', (string)$file->getType()) . ' (' . $file->getMimeType() . ')<br />';
88  $content .= htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
89  $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 />';
90  $content .= '<br />';
91  } else {
92  $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>';
93  }
94 
95  return $content;
96  }
97 }
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement\__construct
‪__construct(private readonly ResourceFactory $resourceFactory,)
Definition: FileInfoElement.php:33
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGEPREVIEW
‪const CONTEXT_IMAGEPREVIEW
Definition: ProcessedFile.php:55
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement
Definition: FileInfoElement.php:32
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:37
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement\render
‪array render()
Definition: FileInfoElement.php:42
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:16
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement\renderFileInformationContent
‪renderFileInformationContent(File $file=null)
Definition: FileInfoElement.php:64
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement\getLanguageService
‪getLanguageService()
Definition: AbstractFormElement.php:456
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:42
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:47
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77