Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Classes/Middleware/MiddlewareActionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Routing\PageArguments;
Expand All @@ -17,6 +18,7 @@
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
Expand Down Expand Up @@ -147,4 +149,49 @@ protected function getLocalizationFromKey(string $keyToTranslate, string $langua

return $keyToTranslate;
}

public function resizeAndCropImage(?FileReference $image, string $width = '2480', string $height = '770', string $cropArea = 'default', bool $absUrl = false): ?string {
if (null == $image) {
return null;
}

if ('svg' == strtolower($image->getOriginalResource()->getExtension())) {
if ($absUrl) {
if (null == $this->siteLanguage) {
return '/'.$image->getOriginalResource()->getPublicUrl();
}

return $this->siteLanguage->getBase()->getScheme().'://'.$this->siteLanguage->getBase()->getHost().'/'.$image->getOriginalResource()->getPublicUrl();
}

return '/'.$image->getOriginalResource()->getPublicUrl();
}

$imageService = GeneralUtility::makeInstance(ImageService::class);
$getImage = $imageService->getImage('', $image, false);

$cropString = null;
if ($getImage->hasProperty('crop') && $getImage->getProperty('crop')) {
$cropString = $getImage->getProperty('crop');
}

$cropVariantCollection = CropVariantCollection::create(strval($cropString));
$cropArea = $cropVariantCollection->getCropArea($cropArea);

$processedImage = $imageService->applyProcessingInstructions($getImage, [
'width' => $width,
'height' => $height,
'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($getImage),
]);

if ($absUrl) {
if (null == $this->siteLanguage) {
return '/'.$processedImage->getPublicUrl();
}

return $this->siteLanguage->getBase()->getScheme().'://'.$this->siteLanguage->getBase()->getHost().'/'.$processedImage->getPublicUrl();
}

return '/'.$processedImage->getPublicUrl();
}
}
8 changes: 6 additions & 2 deletions Classes/Utility/FlexFormUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function getFlexFormValue(array $flexForm, string $fieldName, stri
}

if (is_array($sheetArray)) {
return self::getFlexFormValueFromSheetArray($sheetArray, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('/', $fieldName), $value);
return self::getFlexFormValueFromSheetArray($sheetArray, GeneralUtility::trimExplode('/', $fieldName), $value);
}

return null;
Expand All @@ -93,7 +93,11 @@ public static function getFlexFormValueFromSheetArray(array $sheetArray, array $
}
}
} else {
$tempArr = (array) ($tempArr[strval($v)] ?? []);
if (is_array($tempArr)) {
$tempArr = (array) ($tempArr[strval($v)] ?? []);
} else {
$tempArr = [];
}
}
}

Expand Down