diff --git a/Classes/DataProcessing/DatabaseQueryProcessor.php b/Classes/DataProcessing/DatabaseQueryProcessor.php index aac95c33..f3289df0 100644 --- a/Classes/DataProcessing/DatabaseQueryProcessor.php +++ b/Classes/DataProcessing/DatabaseQueryProcessor.php @@ -93,27 +93,12 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'records'); $records = $cObj->getRecords($tableName, $processorConfiguration); - $processedRecordVariables = $this->processRecordVariables($cObj, $records, $tableName, $processorConfiguration); - - $processedData[$targetVariableName] = $processedRecordVariables; - - return $processedData; - } - - /** - * @param array $records - * @param string $tableName - * @param array $processorConfiguration - * - * @return array - */ - private function processRecordVariables(ContentObjectRenderer $cObj, array $records, string $tableName, array $processorConfiguration): array - { + $request = $cObj->getRequest(); $processedRecordVariables = []; foreach ($records as $key => $record) { $recordContentObjectRenderer = $this->createContentObjectRenderer(); + $recordContentObjectRenderer->setRequest($request); $recordContentObjectRenderer->start($record, $tableName); - $recordContentObjectRenderer->setRequest($cObj->getRequest()); $objConf = []; $objName = '< ' . $tableName; @@ -124,7 +109,7 @@ private function processRecordVariables(ContentObjectRenderer $cObj, array $reco $objConf = $this->typoScriptService->convertPlainArrayToTypoScriptArray(['fields' => $fields, '_typoScriptNodeValue' => 'JSON']); } - $processedRecordVariables[$key] = \json_decode($recordContentObjectRenderer->cObjGetSingle($objName, $objConf), true); + $processedRecordVariables[$key] = $objConf !== [] ? \json_decode($recordContentObjectRenderer->cObjGetSingle($objName, $objConf), true) : $record; $processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]); if (isset($processorConfiguration['overrideFields.'])) { @@ -142,7 +127,9 @@ private function processRecordVariables(ContentObjectRenderer $cObj, array $reco } } - return $processedRecordVariables; + $processedData[$targetVariableName] = $processedRecordVariables; + + return $processedData; } protected function createContentObjectRenderer(): ContentObjectRenderer diff --git a/Configuration/TypoScript/ContentElement/MenuCategorizedContent.typoscript b/Configuration/TypoScript/ContentElement/MenuCategorizedContent.typoscript index d2fb607c..4d7cb33d 100755 --- a/Configuration/TypoScript/ContentElement/MenuCategorizedContent.typoscript +++ b/Configuration/TypoScript/ContentElement/MenuCategorizedContent.typoscript @@ -7,7 +7,7 @@ tt_content.menu_categorized_content { menu = TEXT menu { dataProcessing { - 10 = FriendsOfTYPO3\Headless\DataProcessing\DatabaseQueryProcessor + 10 = headless-database-query 10 { table = tt_content selectFields = {#tt_content}.* @@ -27,12 +27,24 @@ tt_content.menu_categorized_content { orderBy = tt_content.sorting as = menu dataProcessing { - 10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor + 10 = headless-files 10 { references.fieldName = image as = media } } + + fields { + uid = INT + uid { + field = uid + } + + header = TEXT + header { + field = header + } + } } } } diff --git a/Configuration/TypoScript/ContentElement/MenuSection.typoscript b/Configuration/TypoScript/ContentElement/MenuSection.typoscript index 43463dae..ea8270ec 100755 --- a/Configuration/TypoScript/ContentElement/MenuSection.typoscript +++ b/Configuration/TypoScript/ContentElement/MenuSection.typoscript @@ -7,7 +7,7 @@ tt_content.menu_section { menu = TEXT menu { dataProcessing { - 10 = FriendsOfTYPO3\Headless\DataProcessing\MenuProcessor + 10 = headless-menu 10 { appendData = 1 as = menu @@ -30,12 +30,12 @@ tt_content.menu_section { } dataProcessing { - 10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor + 10 = headless-files 10 { references.fieldName = media as = media } - 20 = FriendsOfTYPO3\Headless\DataProcessing\DatabaseQueryProcessor + 20 = headless-database-query 20 { table = tt_content pidInList.field = uid @@ -43,12 +43,24 @@ tt_content.menu_section { where = sectionIndex = 1 orderBy = sorting dataProcessing { - 10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor + 10 = headless-files 10 { references.fieldName = image as = media } } + + fields { + uid = INT + uid { + field = uid + } + + header = TEXT + header { + field = header + } + } } } } diff --git a/Configuration/TypoScript/ContentElement/MenuSectionPages.typoscript b/Configuration/TypoScript/ContentElement/MenuSectionPages.typoscript index b0195309..f4392437 100755 --- a/Configuration/TypoScript/ContentElement/MenuSectionPages.typoscript +++ b/Configuration/TypoScript/ContentElement/MenuSectionPages.typoscript @@ -7,31 +7,43 @@ tt_content.menu_section_pages { menu = TEXT menu { dataProcessing { - 10 = FriendsOfTYPO3\Headless\DataProcessing\MenuProcessor + 10 = headless-menu 10 { appendData = 1 special = directory special.value.field = pages as = menu dataProcessing { - 10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor + 10 = headless-files 10 { references.fieldName = media as = media } - 20 = FriendsOfTYPO3\Headless\DataProcessing\DatabaseQueryProcessor + 20 = headless-database-query 20 { table = tt_content pidInList.field = uid orderBy = sorting as = content dataProcessing { - 10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor + 10 = headless-files 10 { references.fieldName = image as = media } } + + fields { + uid = INT + uid { + field = uid + } + + header = TEXT + header { + field = header + } + } } } } diff --git a/Tests/Functional/ContentTypes/MenuCategorizedContentElementTest.php b/Tests/Functional/ContentTypes/MenuCategorizedContentElementTest.php index ba3a9096..cac77ff5 100644 --- a/Tests/Functional/ContentTypes/MenuCategorizedContentElementTest.php +++ b/Tests/Functional/ContentTypes/MenuCategorizedContentElementTest.php @@ -38,17 +38,13 @@ public function testMenuContentElement() self::assertIsArray($contentElement['content']['menu'][1]); $firstCategorizedContentElement = $contentElement['content']['menu'][0]; - self::assertEquals('17', $firstCategorizedContentElement['id']); - self::assertEquals('header', $firstCategorizedContentElement['type']); - self::assertEquals('default', $firstCategorizedContentElement['appearance']['frameClass']); - self::assertEquals('1', $firstCategorizedContentElement['colPos']); - self::assertEquals('SysCategory3Title', $firstCategorizedContentElement['categories']); + self::assertSame(17, $firstCategorizedContentElement['uid']); + self::assertArrayHasKey('header', $firstCategorizedContentElement); + self::assertArrayHasKey('media', $firstCategorizedContentElement); $secondCategorizedContentElement = $contentElement['content']['menu'][1]; - self::assertEquals('18', $secondCategorizedContentElement['id']); - self::assertEquals('textpic', $secondCategorizedContentElement['type']); - self::assertEquals('default', $secondCategorizedContentElement['appearance']['frameClass']); - self::assertEquals('1', $secondCategorizedContentElement['colPos']); - self::assertEquals('SysCategory3Title', $secondCategorizedContentElement['categories']); + self::assertSame(18, $secondCategorizedContentElement['uid']); + self::assertArrayHasKey('header', $secondCategorizedContentElement); + self::assertArrayHasKey('media', $secondCategorizedContentElement); } }