X-Git-Url: http://git.typo3.org/Packages/TYPO3.CMS.git/blobdiff_plain/121c9ca653e29f139f12105513ebb3140d6609f6..f4a73f2f10263b1a23d7b7a693bbf3adb6351fbc:/typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php diff --git a/typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php b/typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php index 903affac09ad..3d2b9ff8cb3f 100644 --- a/typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php +++ b/typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php @@ -120,7 +120,9 @@ class ImageManipulationElement extends AbstractFormElement parent::__construct($nodeFactory, $data); // Would be great, if we could inject the view here, but since the constructor is in the interface, we can't $this->templateView = GeneralUtility::makeInstance(StandaloneView::class); - $this->templateView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ImageManipulation/ImageCropping.html')); + $this->templateView->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts/')]); + $this->templateView->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials/ImageManipulation/')]); + $this->templateView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ImageManipulation/ImageManipulationElement.html')); $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); } @@ -136,29 +138,30 @@ class ImageManipulationElement extends AbstractFormElement $parameterArray = $this->data['parameterArray']; $config = $this->populateConfiguration($parameterArray['fieldConf']['config']); - if ($config['readOnly']) { - $options = []; - $options['parameterArray'] = [ - 'fieldConf' => [ - 'config' => $parameterArray['fieldConf']['config'], - ], - 'itemFormElValue' => $parameterArray['itemFormElValue'], - ]; - $options['renderType'] = 'none'; - - // Early return in case the field is set to read only - return $this->nodeFactory->create($options)->render(); - } - $file = $this->getFile($this->data['databaseRow'], $config['file_field']); if (!$file) { // Early return in case we do not find a file return $resultArray; } - $config = $this->processConfiguration($config, $parameterArray['itemFormElValue'] ?? '{}'); + $config = $this->processConfiguration($config, $parameterArray['itemFormElValue'], $file); + + $fieldInformationResult = $this->renderFieldInformation(); + $fieldInformationHtml = $fieldInformationResult['html']; + $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); + + $fieldControlResult = $this->renderFieldControl(); + $fieldControlHtml = $fieldControlResult['html']; + $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldControlResult, false); + + $fieldWizardResult = $this->renderFieldWizard(); + $fieldWizardHtml = $fieldWizardResult['html']; + $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false); $arguments = [ + 'fieldInformation' => $fieldInformationHtml, + 'fieldControl' => $fieldControlHtml, + 'fieldWizard' => $fieldWizardHtml, 'isAllowedFileExtension' => in_array(strtolower($file->getExtension()), GeneralUtility::trimExplode(',', strtolower($config['allowedExtensions'])), true), 'image' => $file, 'formEngine' => [ @@ -182,7 +185,8 @@ class ImageManipulationElement extends AbstractFormElement $arguments['formEngine']['validation'] = $this->getValidationDataAsJsonString(['required' => true]); } } - $resultArray['html'] = $this->templateView->renderSection('Element', $arguments); + $this->templateView->assignMultiple($arguments); + $resultArray['html'] = $this->templateView->render(); return $resultArray; } @@ -271,13 +275,18 @@ class ImageManipulationElement extends AbstractFormElement /** * @param array $config * @param string $elementValue + * @param File $file * @return array * @throws \TYPO3\CMS\Core\Imaging\ImageManipulation\InvalidConfigurationException */ - protected function processConfiguration(array $config, string $elementValue) + protected function processConfiguration(array $config, string &$elementValue, File $file) { $cropVariantCollection = CropVariantCollection::create($elementValue, $config['cropVariants']); + if (empty($config['readOnly'])) { + $cropVariantCollection = $cropVariantCollection->applyRatioRestrictionToSelectedCropArea($file); + } $config['cropVariants'] = $cropVariantCollection->asArray(); + $elementValue = (string)$cropVariantCollection; $config['allowedExtensions'] = implode(', ', GeneralUtility::trimExplode(',', $config['allowedExtensions'], true)); return $config; }