‪TYPO3CMS  9.5
FileInfoElement.php
Go to the documentation of this file.
1 <?php
2 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 
24 
31 {
32 
38  public function ‪render(): array
39  {
40  $resultArray = $this->‪initializeResultArray();
41 
42  $fileUid = 0;
43  if ($this->data['tableName'] === 'sys_file') {
44  $fileUid = (int)$this->data['databaseRow']['uid'];
45  } elseif ($this->data['tableName'] === 'sys_file_metadata') {
46  $fileUid = (int)$this->data['databaseRow']['file'][0];
47  }
48 
49  $fileObject = null;
50  if ($fileUid > 0) {
51  $fileObject = ‪ResourceFactory::getInstance()->‪getFileObject($fileUid);
52  }
53  $resultArray['html'] = $this->‪renderFileInformationContent($fileObject);
54  return $resultArray;
55  }
56 
63  protected function ‪renderFileInformationContent(‪File $file = null): string
64  {
66  $lang = ‪$GLOBALS['LANG'];
67 
68  if ($file !== null) {
69  $content = '';
70  if ($file->isMissing()) {
71  $content .= '<span class="label label-danger label-space-right">'
72  . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
73  . '</span>';
74  }
75  if (GeneralUtility::inList(‪$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) {
76  $processedFile = $file->process(‪ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
77  $previewImage = $processedFile->getPublicUrl(true);
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($file->getSize())) . 'bytes)<br />';
87  $content .= ‪BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />';
88  $content .= htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
89  $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<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\Core\Resource\ProcessedFile\CONTEXT_IMAGEPREVIEW
‪const CONTEXT_IMAGEPREVIEW
Definition: ProcessedFile.php:50
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement
Definition: FileInfoElement.php:31
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Backend\Form\Element\AbstractFormElement
Definition: AbstractFormElement.php:31
‪TYPO3\CMS\Backend\Form\Element\FileInfoElement\render
‪array render()
Definition: FileInfoElement.php:38
‪TYPO3\CMS\Backend\Form\Element
Definition: AbstractFormElement.php:2
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:42
‪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:1933
‪$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:63
‪TYPO3\CMS\Core\Resource\ResourceFactory\getFileObject
‪File getFileObject($uid, array $fileData=[])
Definition: ResourceFactory.php:399
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45