Skip to content

Commit

Permalink
[BUGFIX] Improve handling returnFlattenObject in Headless DatabaseQ…
Browse files Browse the repository at this point in the history
…ueryProcessor

Add new flag `returnFlattenLegacy` (enabled by default),
if disabled and combined with `returnFlattenObject`
will return null instead of empty array if no records are found
and will respect "as" setting

Resolves: #797, #739
  • Loading branch information
twoldanski committed Feb 13, 2025
1 parent 0249de3 commit 0d0f6bb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Classes/DataProcessing/DatabaseQueryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
$records = $cObj->getRecords($tableName, $processorConfiguration);
$request = $cObj->getRequest();
$processedRecordVariables = [];

$flattenRow = null;

foreach ($records as $key => $record) {
$recordContentObjectRenderer = $this->createContentObjectRenderer();
$recordContentObjectRenderer->setRequest($request);
Expand Down Expand Up @@ -124,12 +127,21 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
}
}

if ($processorConfiguration['returnFlattenObject'] ?? false) {
return array_shift($processedRecordVariables);
if ((int)($processorConfiguration['returnFlattenObject'] ?? 0)) {
$flattenRow = array_shift($processedRecordVariables);
break;
}
}

$processedData[$targetVariableName] = $processedRecordVariables;
if ($flattenRow !== null && (int)($processorConfiguration['returnFlattenLegacy'] ?? 1)) {
return $flattenRow;
}

if ($processorConfiguration['returnFlattenObject'] ?? 0) {
$processedData[$targetVariableName] = (int)($processorConfiguration['returnFlattenLegacy'] ?? 1) ? $processedRecordVariables : $flattenRow;
} else {
$processedData[$targetVariableName] = $processedRecordVariables;
}

return $processedData;
}
Expand Down

0 comments on commit 0d0f6bb

Please sign in to comment.