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
156 stars 57 forks source link

Problem with DatabaseQueryProcessor #718

Closed MikeHantha closed 4 months ago

MikeHantha commented 4 months ago

We have encountered a problem.

With version 4.2.2 of TYPO3 Headless API it works in a typoscript file with a content processor (FriendsOfTYPO3\Headless\DataProcessing\DatabaseQueryProcessor) selectFields = exttensiontable.* now you get all fields of the table without explicitly setting fields { uid = TEXT uid { field = uid } }

Now we have updated to the current version 4.2.7 and have now encountered the problem that fields must be specified as otherwise an error appears TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor::process(): Argument #3 ($variables) must be of type array, null given, called in headless/Classes/DataProcessing/DatabaseQueryProcessor.php on line 128

Now we have looked at the processor and noticed that the functionality has been changed at https://github.com/TYPO3-Headless/headless/commit/49c24f3d726209c210bceb182ad67e36bba9d495

This line occurs to be the problem: $processedRecordVariables[$key] = \json_decode($recordContentObjectRenderer->cObjGetSingle($objName, $objConf), true);

if fields is empty then $objConf is also empty and the error appears in the next line cause
$processedRecordVariables[$key] is null but needs to be a array with values

$processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]);

Our quick hack is to check if $objConf has values, than use the new version and otherwise use the $record like in the old version

$processedRecordVariables[$key] =count($objConf) ? \json_decode($recordContentObjectRenderer->cObjGetSingle($objName, $objConf), true) : $record

so the old logic is reused only differently.