TYPO3-Headless / headless

TYPO3 Headless JSON API providing content for PWA application (e.g. javaScript apps like nuxt-typo3)
https://t3headless.io
GNU General Public License v2.0
159 stars 60 forks source link

Data with $processorConfiguration option 'returnFlattenObject'==1 should also be returned under $targetVariableName #739

Open dacko-sk opened 4 months ago

dacko-sk commented 4 months ago

When using DatabaseQueryProcessor with returnFlattenObject=1 (only 1 record item expected on output instead of array of records), this method returns data without the $targetVariableName key specified via 'as' option return array_shift($processedRecordVariables); while when returnFlattenObject is not set, the method returns the data under the $targetVariableName key [ $targetVariableName => $processedRecordVariables; ]

Issue in file: https://github.com/TYPO3-Headless/headless/blob/c133e52db4ed55fadc125a5a0b78fa11276afb5f/Classes/DataProcessing/DatabaseQueryProcessor.php#L126

This could be resolved by changing the line 126 to something like $processedRecordVariables = $processedRecordVariables[0] ?? []; without returning it and letting the line 132 to return the whole $processedData as usual - with the data appended under the $targetVariableName key on line 130.

Thanks for checking.