‪TYPO3CMS  9.5
FileThumbnails.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 
26 
32 {
38  public function ‪render(): array
39  {
40  $result = $this->‪initializeResultArray();
41 
42  $table = $this->data['tableName'];
43  $fieldName = $this->data['fieldName'];
44  $row = $this->data['databaseRow'];
45  $parameterArray = $this->data['parameterArray'];
46  $config = $parameterArray['fieldConf']['config'];
47  $selectedItems = $parameterArray['itemFormElValue'];
48 
49  if (!isset($config['internal_type'])
50  || ($config['internal_type'] !== 'file' && $config['internal_type'] !== 'file_reference')
51  ) {
52  // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0. Deprecation logged by TcaMigration class.
53  // Thumbnails only make sense on file and file_reference
54  return $result;
55  }
56 
57  $fileFactory = ‪ResourceFactory::getInstance();
58  $thumbnailsHtml = [];
59  foreach ($selectedItems as $selectedItem) {
60  $uidOrPath = $selectedItem['uidOrPath'];
62  $fileObject = $fileFactory->getFileObject($uidOrPath);
63  if (!$fileObject->isMissing()) {
64  $extension = $fileObject->getExtension();
65  if (GeneralUtility::inList(
66  ‪$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
67  $extension
68  )
69  ) {
70  $thumbnailsHtml[] = '<li>';
71  $thumbnailsHtml[] = '<span class="thumbnail">';
72  $thumbnailsHtml[] = $fileObject->process(‪ProcessedFile::CONTEXT_IMAGEPREVIEW, [])->getPublicUrl(true);
73  $thumbnailsHtml[] = '</span>';
74  $thumbnailsHtml[] = '</li>';
75  }
76  }
77  } else {
78  $rowCopy = [];
79  $rowCopy[$fieldName] = $uidOrPath;
80  try {
82  $rowCopy,
83  $table,
84  $fieldName,
85  '',
86  '',
87  $config['uploadfolder'],
88  0,
89  ' align="middle"'
90  );
91  $thumbnailsHtml[] =
92  '<li>'
93  . '<span class="thumbnail">'
94  . $icon
95  . '</span>'
96  . '</li>';
97  } catch (\‪Exception $exception) {
98  $message = $exception->getMessage();
99  $flashMessage = GeneralUtility::makeInstance(
100  FlashMessage::class,
101  $message,
102  '',
104  true
105  );
106  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
107  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
108  $defaultFlashMessageQueue->enqueue($flashMessage);
109  $this->logger->warning($message, ['table' => $table, 'row' => $row]);
110  }
111  }
112  }
113 
114  $html = [];
115  if (!empty($thumbnailsHtml)) {
116  $html[] = '<ul class="list-inline">';
117  $html[] = implode(LF, $thumbnailsHtml);
118  $html[] = '</ul>';
119  }
120 
121  $result['html'] = implode(LF, $html);
122  return $result;
123  }
124 }
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGEPREVIEW
‪const CONTEXT_IMAGEPREVIEW
Definition: ProcessedFile.php:50
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:73
‪TYPO3\CMS\Backend\Form\FieldWizard\FileThumbnails\render
‪array render()
Definition: FileThumbnails.php:38
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Backend\Utility\BackendUtility\thumbCode
‪static string thumbCode( $row, $table, $field, $backPath='', $thumbScript='', $uploaddir=null, $abs=0, $tparams='', $size='', $linkInfoPopup=true)
Definition: BackendUtility.php:1338
‪TYPO3\CMS\Backend\Form\FieldWizard
Definition: DefaultLanguageDifferences.php:3
‪TYPO3\CMS\Backend\Form\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:42
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Backend\Form\FieldWizard\FileThumbnails
Definition: FileThumbnails.php:32