Skip to content

Commit

Permalink
feat: pass all props to file processing (TYPO3-Headless#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kubilay Melnikov committed Oct 21, 2022
1 parent 0038d46 commit 3f1c973
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions Classes/DataProcessing/FilesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,10 @@ public function process(
return $processedData;
}

$dimensions = [];
$properties = [];

if (isset($processorConfiguration['processingConfiguration.'])) {
$dimensions = [
'width' => $cObj->stdWrapValue('width', $processorConfiguration['processingConfiguration.'] ?? [], null),
'height' => $cObj->stdWrapValue('height', $processorConfiguration['processingConfiguration.'] ?? [], null),
'minWidth' => $cObj->stdWrapValue('minWidth', $processorConfiguration['processingConfiguration.'] ?? [], null),
'minHeight' => $cObj->stdWrapValue('minHeight', $processorConfiguration['processingConfiguration.'] ?? [], null),
'maxWidth' => $cObj->stdWrapValue('maxWidth', $processorConfiguration['processingConfiguration.'] ?? [], null),
'maxHeight' => $cObj->stdWrapValue('maxHeight', $processorConfiguration['processingConfiguration.'] ?? [], null),
];
$properties = $cObj->stdWrapValue('processingConfiguration', $processorConfiguration, null);
}

$this->contentObjectRenderer = $cObj;
Expand All @@ -98,7 +91,7 @@ public function process(
);

$this->fileObjects = $this->fetchData();
$processedData[$targetFieldName] = $this->processFiles($dimensions);
$processedData[$targetFieldName] = $this->processFiles($properties);

return $this->removeDataIfnotAppendInConfiguration($processorConfiguration, $processedData);
}
Expand Down Expand Up @@ -169,27 +162,27 @@ protected function fetchData(): array
}

/**
* @param array $dimensions
* @param array $properties
* @return array|null
*/
protected function processFiles(array $dimensions = []): ?array
protected function processFiles(array $properties = []): ?array
{
$data = [];
$cropVariant = $this->processorConfiguration['processingConfiguration.']['cropVariant'] ?? 'default';

foreach ($this->fileObjects as $key => $fileObject) {
if (isset($this->processorConfiguration['processingConfiguration.']['autogenerate.'])) {
$file = $this->getFileUtility()->processFile($fileObject, $dimensions, $cropVariant);
$targetWidth = (int)($dimensions['width'] ?: $file['properties']['dimensions']['width']);
$targetHeight = (int)($dimensions['height'] ?: $file['properties']['dimensions']['height']);
$file = $this->getFileUtility()->processFile($fileObject, $properties, $cropVariant);
$targetWidth = (int)($properties['width'] ?: $file['properties']['dimensions']['width']);
$targetHeight = (int)($properties['height'] ?: $file['properties']['dimensions']['height']);

if (isset($this->processorConfiguration['processingConfiguration.']['autogenerate.']['retina2x']) &&
(int)$this->processorConfiguration['processingConfiguration.']['autogenerate.']['retina2x'] === 1 &&
($targetWidth || $targetHeight)) {
$file['urlRetina'] = $this->getFileUtility()->processFile(
$fileObject,
array_merge(
$dimensions,
$properties,
[
'width' => $targetWidth * FileUtility::RETINA_RATIO,
'height' => $targetHeight * FileUtility::RETINA_RATIO,
Expand All @@ -205,7 +198,7 @@ protected function processFiles(array $dimensions = []): ?array
$file['urlLqip'] = $this->getFileUtility()->processFile(
$fileObject,
array_merge(
$dimensions,
$properties,
[
'width' => $targetWidth * FileUtility::LQIP_RATIO,
'height' => $targetHeight * FileUtility::LQIP_RATIO,
Expand All @@ -217,7 +210,7 @@ protected function processFiles(array $dimensions = []): ?array

$data[] = $file;
} else {
$data[$key] = $this->getFileUtility()->processFile($fileObject, $dimensions, $cropVariant);
$data[$key] = $this->getFileUtility()->processFile($fileObject, $properties, $cropVariant);

$crop = $fileObject->getProperty('crop');

Expand All @@ -226,7 +219,7 @@ protected function processFiles(array $dimensions = []): ?array

if (is_array($cropVariants) && count($cropVariants) > 1) {
foreach (array_keys($cropVariants) as $cropVariantName) {
$file = $this->getFileUtility()->processFile($fileObject, $dimensions, $cropVariantName);
$file = $this->getFileUtility()->processFile($fileObject, $properties, $cropVariantName);
$data[$key]['cropVariants'][$cropVariantName] = $file;
}
}
Expand Down

0 comments on commit 3f1c973

Please sign in to comment.