‪TYPO3CMS  10.4
OtherLanguageThumbnails.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 
29 
37 {
43  public function ‪render(): array
44  {
45  $result = $this->‪initializeResultArray();
46  $fieldConfig = $this->data['parameterArray']['fieldConf'];
47  $l10nDisplay = $fieldConfig['l10n_display'] ?? '';
48  $cropVariants = $fieldConfig['config']['cropVariants'] ?? ['default' => []];
49  $defaultLanguageRow = $this->data['defaultLanguageRow'] ?? null;
50 
51  if (!is_array($defaultLanguageRow)
52  || !is_array($cropVariants)
53  || $cropVariants === []
54  || $fieldConfig['config']['type'] !== 'imageManipulation'
55  || GeneralUtility::inList($l10nDisplay, 'hideDiff')
56  || GeneralUtility::inList($l10nDisplay, 'defaultAsReadonly')
57  ) {
58  return $result;
59  }
60 
61  $html = [];
62  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
63  $languages = [$defaultLanguageRow['sys_language_uid'] => $defaultLanguageRow] + ($this->data['additionalLanguageRows'] ?? []);
64 
65  foreach ($languages as $sysLanguageUid => $languageRow) {
66  $file = null;
67  $fileUid = (int)($languageRow['uid_local'] ?? 0);
68 
69  if (!$fileUid || $languageRow['table_local'] !== 'sys_file') {
70  continue;
71  }
72 
73  try {
74  $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
75  } catch (‪FileDoesNotExistException|\InvalidArgumentException $e) {
76  continue;
77  }
78 
79  $processedImages = [];
80  $cropVariantCollection = ‪CropVariantCollection::create((string)($languageRow['crop'] ?? ''), $cropVariants);
81 
82  foreach (array_keys($cropVariants) as $variant) {
83  $processedImages[] = ‪FormEngineUtility::getIconHtml(
84  $file
85  ->process(
87  [
88  'maxWidth' => '145',
89  'maxHeight' => '45',
90  'crop' => $cropVariantCollection->getCropArea($variant)->makeAbsoluteBasedOnFile($file)
91  ]
92  )
93  ->getPublicUrl() ?? '',
94  $languageRow['title'] ?? $file->getProperty('title') ?? '',
95  $languageRow['alternative'] ?? $file->getProperty('alternative') ?? ''
96  );
97  }
98 
99  if ($processedImages !== []) {
100  $iconIdentifier = $this->data['systemLanguageRows'][(int)$sysLanguageUid]['flagIconIdentifier'] ?? 'flags-multiple';
101  $html[] = '<div class="t3-form-original-language">';
102  $html[] = $iconFactory->getIcon($iconIdentifier, ‪Icon::SIZE_SMALL)->render();
103  $html[] = implode(LF, $processedImages);
104  $html[] = '</div>';
105  }
106  }
107 
108  $result['html'] = implode(LF, $html);
109  return $result;
110  }
111 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:90
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageThumbnails
Definition: OtherLanguageThumbnails.php:37
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGECROPSCALEMASK
‪const CONTEXT_IMAGECROPSCALEMASK
Definition: ProcessedFile.php:58
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageThumbnails\render
‪array render()
Definition: OtherLanguageThumbnails.php:43
‪TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
Definition: FileDoesNotExistException.php:22
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility
Definition: FormEngineUtility.php:39
‪TYPO3\CMS\Backend\Form\FieldWizard
Definition: DefaultLanguageDifferences.php:18
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getIconHtml
‪static string getIconHtml($icon, $alt='', $title='')
Definition: FormEngineUtility.php:121
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:44
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection
Definition: CropVariantCollection.php:23
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection\create
‪static CropVariantCollection create(string $jsonString, array $tcaConfig=[])
Definition: CropVariantCollection.php:42