‪TYPO3CMS  10.4
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 
26 
33 {
34 
40  public function ‪render(): array
41  {
42  $resultArray = $this->‪initializeResultArray();
43 
44  $fileUid = 0;
45  if ($this->data['tableName'] === 'sys_file') {
46  $fileUid = (int)$this->data['databaseRow']['uid'];
47  } elseif ($this->data['tableName'] === 'sys_file_metadata') {
48  $fileUid = (int)$this->data['databaseRow']['file'][0];
49  }
50 
51  $fileObject = null;
52  if ($fileUid > 0) {
53  $fileObject = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
54  }
55  $resultArray['html'] = $this->‪renderFileInformationContent($fileObject);
56  return $resultArray;
57  }
58 
65  protected function ‪renderFileInformationContent(‪File $file = null): string
66  {
68  $lang = ‪$GLOBALS['LANG'];
69 
70  if ($file !== null) {
71  $content = '';
72  if ($file->isMissing()) {
73  $content .= '<span class="label label-danger label-space-right">'
74  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
75  . '</span>';
76  }
77  if ($file->isImage()) {
78  $processedFile = $file->process(‪ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
79  $previewImage = $processedFile->getPublicUrl(true);
80  if ($previewImage) {
81  $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' .
82  'width="' . $processedFile->getProperty('width') . '" ' .
83  'height="' . $processedFile->getProperty('height') . '" ' .
84  'alt="" class="t3-tceforms-sysfile-imagepreview" />';
85  }
86  }
87  $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
88  $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize((int)$file->getSize())) . 'bytes)<br />';
89  $content .= ‪BackendUtility::getProcessedValue('sys_file', 'type', (string)$file->getType()) . ' (' . $file->getMimeType() . ')<br />';
90  $content .= htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
91  $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />';
92  $content .= '<br />';
93  } else {
94  $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>';
95  }
96 
97  return $content;
98  }
99 }
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGEPREVIEW
‪const CONTEXT_IMAGEPREVIEW
Definition: ProcessedFile.php:52
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:90
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement
Definition: FileInfoElement.php:33
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:32
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement\render
‪array render()
Definition: FileInfoElement.php:40
‪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\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:44
‪TYPO3\CMS\Backend\Utility\BackendUtility\getProcessedValue
‪static string null getProcessedValue( $table, $col, $value, $fixed_lgd_chars=0, $defaultPassthrough=false, $noRecordLookup=false, $uid=0, $forceResult=true, $pid=0)
Definition: BackendUtility.php:1664
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement\renderFileInformationContent
‪string renderFileInformationContent(File $file=null)
Definition: FileInfoElement.php:65
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46