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