|
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
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Backend\Form\FieldWizard; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Backend\Form\AbstractNode; |
|
21
|
|
|
use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility; |
|
22
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
|
23
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
|
24
|
|
|
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; |
|
25
|
|
|
use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException; |
|
26
|
|
|
use TYPO3\CMS\Core\Resource\ProcessedFile; |
|
27
|
|
|
use TYPO3\CMS\Core\Resource\ResourceFactory; |
|
28
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Render cropped thumbnails for default and additional preview |
|
32
|
|
|
* languages by respecting the corresponding cropping configuration. |
|
33
|
|
|
* |
|
34
|
|
|
* @internal |
|
35
|
|
|
*/ |
|
36
|
|
|
class OtherLanguageThumbnails extends AbstractNode |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* Render cropped thumbnails from other language rows |
|
40
|
|
|
* |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
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( |
|
86
|
|
|
ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, |
|
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
|
|
|
} |
|
112
|
|
|
|