TYPO3 CMS  TYPO3_8-7
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  // Thumbnails only make sense on file and file_reference
53  return $result;
54  }
55 
56  $fileFactory = ResourceFactory::getInstance();
57  $thumbnailsHtml = [];
58  foreach ($selectedItems as $selectedItem) {
59  $uidOrPath = $selectedItem['uidOrPath'];
61  $fileObject = $fileFactory->getFileObject($uidOrPath);
62  if (!$fileObject->isMissing()) {
63  $extension = $fileObject->getExtension();
65  $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
66  $extension
67  )
68  ) {
69  $thumbnailsHtml[] = '<li>';
70  $thumbnailsHtml[] = '<span class="thumbnail">';
71  $thumbnailsHtml[] = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, [])->getPublicUrl(true);
72  $thumbnailsHtml[] = '</span>';
73  $thumbnailsHtml[] = '</li>';
74  }
75  }
76  } else {
77  $rowCopy = [];
78  $rowCopy[$fieldName] = $uidOrPath;
79  try {
80  $icon = BackendUtility::thumbCode(
81  $rowCopy,
82  $table,
83  $fieldName,
84  '',
85  '',
86  $config['uploadfolder'],
87  0,
88  ' align="middle"'
89  );
90  $thumbnailsHtml[] =
91  '<li>'
92  . '<span class="thumbnail">'
93  . $icon
94  . '</span>'
95  . '</li>';
96  } catch (\Exception $exception) {
97  $message = $exception->getMessage();
98  $flashMessage = GeneralUtility::makeInstance(
99  FlashMessage::class,
100  $message,
101  '',
103  true
104  );
105  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
106  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
107  $defaultFlashMessageQueue->enqueue($flashMessage);
108  $logMessage = $message . ' (' . $table . ':' . $row['uid'] . ')';
109  GeneralUtility::sysLog($logMessage, 'core', GeneralUtility::SYSLOG_SEVERITY_WARNING);
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 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']