2 declare(strict_types = 1);
48 'file_field' =>
'uid_local',
49 'allowedExtensions' =>
null,
52 'title' =>
'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.crop_variant.default',
53 'allowedAspectRatios' => [
55 'title' =>
'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
59 'title' =>
'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.3_2',
63 'title' =>
'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
67 'title' =>
'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.1_1',
71 'title' =>
'LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
75 'selectedRatio' =>
'NaN',
93 'renderType' =>
'tcaDescription',
103 'localizationStateSelector' => [
104 'renderType' =>
'localizationStateSelector',
106 'otherLanguageContent' => [
107 'renderType' =>
'otherLanguageContent',
109 'localizationStateSelector'
112 'defaultLanguageDifferences' => [
113 'renderType' =>
'defaultLanguageDifferences',
115 'otherLanguageContent',
138 $this->templateView = GeneralUtility::makeInstance(StandaloneView::class);
139 $this->templateView->setLayoutRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Layouts/')]);
140 $this->templateView->setPartialRootPaths([GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Partials/ImageManipulation/')]);
141 $this->templateView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
'EXT:backend/Resources/Private/Templates/ImageManipulation/ImageManipulationElement.html'));
142 $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
154 $parameterArray = $this->data[
'parameterArray'];
157 $file = $this->
getFile($this->data[
'databaseRow'], $config[
'file_field']);
166 $fieldInformationHtml = $fieldInformationResult[
'html'];
170 $fieldControlHtml = $fieldControlResult[
'html'];
174 $fieldWizardHtml = $fieldWizardResult[
'html'];
178 'fieldInformation' => $fieldInformationHtml,
179 'fieldControl' => $fieldControlHtml,
180 'fieldWizard' => $fieldWizardHtml,
181 'isAllowedFileExtension' => in_array(strtolower($file->getExtension()), GeneralUtility::trimExplode(
',', strtolower($config[
'allowedExtensions'])),
true),
185 'value' => $parameterArray[
'itemFormElValue'],
186 'name' => $parameterArray[
'itemFormElName']
192 'wizardPayload' => json_encode($this->
getWizardPayload($config[
'cropVariants'], $file)),
193 'previewUrl' => $this->
getPreviewUrl($this->data[
'databaseRow'], $file),
196 if ($arguments[
'isAllowedFileExtension']) {
197 $resultArray[
'requireJsModules'][] = [
198 'TYPO3/CMS/Backend/ImageManipulation' =>
'function (ImageManipulation) {top.require(["cropper"], function() { ImageManipulation.initializeTrigger(); }); }'
201 if (GeneralUtility::inList($config[
'eval'],
'required')) {
205 $this->templateView->assignMultiple($arguments);
206 $resultArray[
'html'] = $this->templateView->render();
218 protected function getFile(array $row, $fieldName)
221 $fileUid = !empty($row[$fieldName]) ? $row[$fieldName] :
null;
222 if (is_array($fileUid) && isset($fileUid[0][
'uid'])) {
223 $fileUid = $fileUid[0][
'uid'];
228 }
catch (FileDoesNotExistException $e) {
229 }
catch (\InvalidArgumentException $e) {
245 'databaseRow' => $databaseRow,
247 'previewUrl' => $previewUrl,
249 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'Backend/Form/Element/ImageManipulationElement'][
'previewUrl'] ?? [] as $listener) {
250 $previewUrl = GeneralUtility::callUserFunction($listener, $hookParameters, $this);
265 if (isset($baseConfiguration[
'cropVariants'])) {
269 $config = array_replace_recursive(
$defaultConfig, $baseConfiguration);
271 if (!is_array($config[
'cropVariants'])) {
276 foreach ($config[
'cropVariants'] as $id => $cropVariant) {
278 if (!empty($cropVariant[
'disabled'])) {
282 if (empty($cropVariant[
'cropArea'])) {
285 $cropVariants[$id] = $cropVariant;
288 $config[
'cropVariants'] = $cropVariants;
291 if ($config[
'allowedExtensions'] ===
null) {
292 $config[
'allowedExtensions'] =
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'imagefile_ext'];
307 if (empty($config[
'readOnly']) && !empty($file->
getProperty(
'width'))) {
308 $cropVariantCollection = $cropVariantCollection->applyRatioRestrictionToSelectedCropArea($file);
309 $elementValue = (string)$cropVariantCollection;
311 $config[
'cropVariants'] = $cropVariantCollection->asArray();
312 $config[
'allowedExtensions'] = implode(
', ', GeneralUtility::trimExplode(
',', $config[
'allowedExtensions'],
true));
321 return (
string)$this->uriBuilder->buildUriFromRoute($this->wizardRouteName);
332 'cropVariants' => $cropVariants,
335 $uriArguments[
'arguments'] = json_encode($arguments);
336 $uriArguments[
'signature'] = GeneralUtility::hmac($uriArguments[
'arguments'], $this->wizardRouteName);
338 return $uriArguments;