From 001438238337e9b2f175b12e3ca7cfe45a1bd3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Fri, 15 Sep 2023 17:26:37 +0200 Subject: [PATCH 01/18] [FEATURE] Add CategoriesProcessor --- .../DataProcessing/CategoriesProcessor.php | 114 ++++++++++++++++++ Configuration/Services.php | 2 + 2 files changed, 116 insertions(+) create mode 100644 Classes/DataProcessing/CategoriesProcessor.php diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php new file mode 100644 index 00000000..19e25e66 --- /dev/null +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -0,0 +1,114 @@ +checkIf($processorConfiguration['if.'])) { + return $processedData; + } + + $relationTable = $cObj->stdWrapValue('relationTable', $processorConfiguration); + $relationUid = (int)$cObj->stdWrapValue('relationUid', $processorConfiguration); + $categoryIdList = (string)$cObj->stdWrapValue('categoryIdList', $processorConfiguration, ''); + + $defaultQueryConfig = [ + 'pidInList' => 'root', + 'selectFields' => 'uid AS id,title' + ]; + + if (empty($categoryIdList) === false) { + $queryConfig = [ + 'where' => '{#sys_category.uid} IN (' . $categoryIdList . ')', + 'languageField' => 0 + ]; + } + + if (empty($relationTable) === false && empty($relationUid) === false) { + $queryConfig = [ + 'join' => 'sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid', + 'where' => '({#sys_category_record_mm.tablenames} = \'' . $relationTable . '\' AND {#sys_category_record_mm.uid_foreign}=' . $relationUid . ')' + ]; + } + + ArrayUtility::mergeRecursiveWithOverrule( + $queryConfig, + $defaultQueryConfig + ); + + $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'categories'); + $categories = $cObj->getRecords('sys_category', $queryConfig); + + $processedRecordVariables = []; + foreach ($categories as $key => $category) { + $processedRecordVariables[$key] = ArrayUtility::filterRecursive($category, function ($key) { + return $key === 'id' || $key === 'title'; + }, ARRAY_FILTER_USE_KEY); + } + + $processedData[$targetVariableName] = $processedRecordVariables; + + return $processedData; + } +} diff --git a/Configuration/Services.php b/Configuration/Services.php index 5f0196e6..8f59c5d8 100644 --- a/Configuration/Services.php +++ b/Configuration/Services.php @@ -14,6 +14,7 @@ use FriendsOfTYPO3\Headless\ContentObject\IntegerContentObject; use FriendsOfTYPO3\Headless\ContentObject\JsonContentContentObject; use FriendsOfTYPO3\Headless\ContentObject\JsonContentObject; +use FriendsOfTYPO3\Headless\DataProcessing\CategoriesProcessor; use FriendsOfTYPO3\Headless\DataProcessing\DatabaseQueryProcessor; use FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor; use FriendsOfTYPO3\Headless\DataProcessing\FlexFormProcessor; @@ -120,6 +121,7 @@ GalleryProcessor::class => ['identifier' => 'headless-gallery', 'share' => false, 'public' => false], DatabaseQueryProcessor::class => ['identifier' => 'headless-database-query', 'share' => false, 'public' => true], FlexFormProcessor::class => ['identifier' => 'headless-flex-form', 'share' => false, 'public' => false], + CategoriesProcessor::class => ['identifier' => 'headless-categories', 'share' => false, 'public' => false], ] as $class => $processorConfig ) { $service = $services->set($class) From f7b14a16317d1bb87bc0a6ef7d9539bed2acd176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Fri, 15 Sep 2023 17:27:30 +0200 Subject: [PATCH 02/18] [FEATURE] Use CategoriesProcessor in page and content element TypoScript --- .../PageConfiguration.typoscript | 13 +++++- .../ContentElement/ContentElement.typoscript | 43 ++++--------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/Configuration/TypoScript/Configuration/PageConfiguration.typoscript b/Configuration/TypoScript/Configuration/PageConfiguration.typoscript index 3a1c81f0..733029fc 100644 --- a/Configuration/TypoScript/Configuration/PageConfiguration.typoscript +++ b/Configuration/TypoScript/Configuration/PageConfiguration.typoscript @@ -51,7 +51,18 @@ page { } } meta =< lib.meta - categories =< lib.categories + categories = JSON + categories { + dataProcessing { + 10 = headless-categories + 10 { + relationTable = pages + relationUid.field = uid + + as = categories + } + } + } breadcrumbs =< lib.breadcrumbs appearance =< lib.pageAppearance content =< lib.content diff --git a/Configuration/TypoScript/ContentElement/ContentElement.typoscript b/Configuration/TypoScript/ContentElement/ContentElement.typoscript index 4154624f..08d8701a 100755 --- a/Configuration/TypoScript/ContentElement/ContentElement.typoscript +++ b/Configuration/TypoScript/ContentElement/ContentElement.typoscript @@ -14,41 +14,16 @@ lib.contentElement { colPos { field = colPos } - categories = COA + categories = JSON categories { - 10 = CONTENT - 10 { - table = sys_category - select { - pidInList = root - selectFields = sys_category.title - join = sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid - where { - field = uid - wrap = AND sys_category_record_mm.tablenames = 'tt_content' AND sys_category_record_mm.uid_foreign=| - } - } - renderObj = TEXT - renderObj { - field = title - wrap = |###BREAK### - } - } - stdWrap.split { - token = ###BREAK### - cObjNum = 1 |*|2|*| 3 - 1 { - current = 1 - stdWrap.wrap = | - } - 2 { - current = 1 - stdWrap.wrap = ,| - } - 3 { - current = 1 - stdWrap.wrap = | - } + dataProcessing { + 10 = headless-categories + 10 { + relationTable = tt_content + relationUid.field = uid + + as = categories + } } } appearance =< lib.appearance From af1e9d29d7a5447ed4ded6a68601aa0e6acda99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Fri, 15 Sep 2023 17:43:17 +0200 Subject: [PATCH 03/18] [DOCS] Add CategoriesProcessor to the README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c75f03f0..1f60e07a 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,9 @@ Used for processing flexforms. ### RootSitesProcessor Render your all headless sites configuration for your frontend application. +### CatregoriesProcessor +This processor returns an array of categories (`id` and `title`) by either a +relation record or a comma separated list of category uids ## Contributing ![Alt](https://repobeats.axiom.co/api/embed/197db91cad9195bb15a06c91fda5a215bff26cba.svg) From 50b1b8c327d99655c132bb9ea9fac2323a11b2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Fri, 15 Sep 2023 17:47:02 +0200 Subject: [PATCH 04/18] [DOCS] Correct typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f60e07a..bfbaacb7 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ Used for processing flexforms. ### RootSitesProcessor Render your all headless sites configuration for your frontend application. -### CatregoriesProcessor +### CategoriesProcessor This processor returns an array of categories (`id` and `title`) by either a relation record or a comma separated list of category uids From 40de57b0194d7dba741f723ce56e890d68c536bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Sat, 16 Sep 2023 12:11:37 +0200 Subject: [PATCH 05/18] [TASK] Correct linter errors --- Classes/DataProcessing/CategoriesProcessor.php | 10 ++++------ .../ContentElement/ContentElement.typoscript | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index 19e25e66..d1d9b7e3 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -62,9 +62,7 @@ public function process( array $contentObjectConfiguration, array $processorConfiguration, array $processedData - ): array - { - + ): array { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } @@ -75,20 +73,20 @@ public function process( $defaultQueryConfig = [ 'pidInList' => 'root', - 'selectFields' => 'uid AS id,title' + 'selectFields' => 'uid AS id,title', ]; if (empty($categoryIdList) === false) { $queryConfig = [ 'where' => '{#sys_category.uid} IN (' . $categoryIdList . ')', - 'languageField' => 0 + 'languageField' => 0, ]; } if (empty($relationTable) === false && empty($relationUid) === false) { $queryConfig = [ 'join' => 'sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid', - 'where' => '({#sys_category_record_mm.tablenames} = \'' . $relationTable . '\' AND {#sys_category_record_mm.uid_foreign}=' . $relationUid . ')' + 'where' => '({#sys_category_record_mm.tablenames} = \'' . $relationTable . '\' AND {#sys_category_record_mm.uid_foreign}=' . $relationUid . ')', ]; } diff --git a/Configuration/TypoScript/ContentElement/ContentElement.typoscript b/Configuration/TypoScript/ContentElement/ContentElement.typoscript index 08d8701a..f0a31dd0 100755 --- a/Configuration/TypoScript/ContentElement/ContentElement.typoscript +++ b/Configuration/TypoScript/ContentElement/ContentElement.typoscript @@ -23,7 +23,7 @@ lib.contentElement { relationUid.field = uid as = categories - } + } } } appearance =< lib.appearance From c81ca68c4e4b65929f1da8c8148b7120e5a8a451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Sat, 16 Sep 2023 12:17:06 +0200 Subject: [PATCH 06/18] [TASK] Correct php linter errors --- Classes/DataProcessing/CategoriesProcessor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index d1d9b7e3..3dd4a417 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -11,7 +11,6 @@ namespace FriendsOfTYPO3\Headless\DataProcessing; - use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; From 72a5db68e41e4daf89a6ac9c795ac42712c30437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n?= Date: Wed, 20 Sep 2023 12:24:55 +0200 Subject: [PATCH 07/18] [FEATURE] Get categories by relation field instead of uid --- .../DataProcessing/CategoriesProcessor.php | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index 3dd4a417..0a4c16b2 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -16,14 +16,13 @@ use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; /* - * Example usage (get categories by relation record): + * Example usage (get categories by relation field): categories = JSON categories { dataProcessing { 10 = headless-categories 10 { - relationTable = pages - relationUid.field = uid + relation.fieldName = categories as = categories } @@ -66,15 +65,13 @@ public function process( return $processedData; } - $relationTable = $cObj->stdWrapValue('relationTable', $processorConfiguration); - $relationUid = (int)$cObj->stdWrapValue('relationUid', $processorConfiguration); - $categoryIdList = (string)$cObj->stdWrapValue('categoryIdList', $processorConfiguration, ''); - $defaultQueryConfig = [ 'pidInList' => 'root', 'selectFields' => 'uid AS id,title', ]; + $queryConfig = []; + $categoryIdList = (string)$cObj->stdWrapValue('categoryIdList', $processorConfiguration, ''); if (empty($categoryIdList) === false) { $queryConfig = [ 'where' => '{#sys_category.uid} IN (' . $categoryIdList . ')', @@ -82,11 +79,24 @@ public function process( ]; } - if (empty($relationTable) === false && empty($relationUid) === false) { - $queryConfig = [ - 'join' => 'sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid', - 'where' => '({#sys_category_record_mm.tablenames} = \'' . $relationTable . '\' AND {#sys_category_record_mm.uid_foreign}=' . $relationUid . ')', - ]; + + if (!empty($processorConfiguration['relation.'])) { + $referenceConfiguration = $processorConfiguration['relation.']; + $relationField = $cObj->stdWrapValue('fieldName', $referenceConfiguration ?? []); + if (!empty($relationField)) { + $relationTable = $cObj->stdWrapValue('table', $referenceConfiguration, $cObj->getCurrentTable()); + + if (!empty($relationTable)) { + $queryConfig = [ + 'join' => 'sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid', + 'where' => '({#sys_category_record_mm.tablenames} = \'' . $relationTable . '\' AND {#sys_category_record_mm.fieldname} = \'' . $relationField . '\' AND {#sys_category_record_mm.uid_foreign}=' . $cObj->data['uid'] . ')', + ]; + } + } + } + + if (empty($queryConfig) === true) { + return $processedData; } ArrayUtility::mergeRecursiveWithOverrule( From 8bd3aeb27b970430698487c8424363e79013f50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n?= Date: Wed, 20 Sep 2023 12:27:32 +0200 Subject: [PATCH 08/18] [FEATURE] Use new processorConfig for pages --- .../TypoScript/Configuration/PageConfiguration.typoscript | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Configuration/TypoScript/Configuration/PageConfiguration.typoscript b/Configuration/TypoScript/Configuration/PageConfiguration.typoscript index 733029fc..7fb945ff 100644 --- a/Configuration/TypoScript/Configuration/PageConfiguration.typoscript +++ b/Configuration/TypoScript/Configuration/PageConfiguration.typoscript @@ -56,9 +56,7 @@ page { dataProcessing { 10 = headless-categories 10 { - relationTable = pages - relationUid.field = uid - + relation.fieldName = categories as = categories } } From 015e76df547f6e54ea9cd0593f82637a8a564e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n?= Date: Wed, 20 Sep 2023 12:28:40 +0200 Subject: [PATCH 09/18] [FEATURE] Use new processorConfig for content --- .../TypoScript/ContentElement/ContentElement.typoscript | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Configuration/TypoScript/ContentElement/ContentElement.typoscript b/Configuration/TypoScript/ContentElement/ContentElement.typoscript index f0a31dd0..0ca61eb1 100755 --- a/Configuration/TypoScript/ContentElement/ContentElement.typoscript +++ b/Configuration/TypoScript/ContentElement/ContentElement.typoscript @@ -19,8 +19,7 @@ lib.contentElement { dataProcessing { 10 = headless-categories 10 { - relationTable = tt_content - relationUid.field = uid + relation.fieldName = categories as = categories } From ebfaddaa1035ea042540d395b35fcea06d1bf94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n?= Date: Thu, 21 Sep 2023 09:00:45 +0200 Subject: [PATCH 10/18] [TASK] Properly quote fields in query --- Classes/DataProcessing/CategoriesProcessor.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index 0a4c16b2..e59f3f3f 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -67,7 +67,7 @@ public function process( $defaultQueryConfig = [ 'pidInList' => 'root', - 'selectFields' => 'uid AS id,title', + 'selectFields' => '{#sys_category}.{#uid} AS id, {#sys_category}.{#title}', ]; $queryConfig = []; @@ -79,7 +79,6 @@ public function process( ]; } - if (!empty($processorConfiguration['relation.'])) { $referenceConfiguration = $processorConfiguration['relation.']; $relationField = $cObj->stdWrapValue('fieldName', $referenceConfiguration ?? []); @@ -88,8 +87,8 @@ public function process( if (!empty($relationTable)) { $queryConfig = [ - 'join' => 'sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid', - 'where' => '({#sys_category_record_mm.tablenames} = \'' . $relationTable . '\' AND {#sys_category_record_mm.fieldname} = \'' . $relationField . '\' AND {#sys_category_record_mm.uid_foreign}=' . $cObj->data['uid'] . ')', + 'join' => '{#sys_category_record_mm} on {#sys_category_record_mm}.{#uid_local} = {#sys_category}.{#uid}', + 'where' => '({#sys_category_record_mm}.{#tablenames} = \'' . $relationTable . '\' AND {#sys_category_record_mm}.{#fieldname} = \'' . $relationField . '\' AND {#sys_category_record_mm}.{#uid_foreign}=' . $cObj->data['uid'] . ')', ]; } } From cef398b2625e565e666baade4108cb1481aa758c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n?= Date: Mon, 2 Oct 2023 12:57:37 +0000 Subject: [PATCH 11/18] [TASK] Correct tests --- Tests/Functional/ContentTypes/BaseContentTypeTest.php | 2 +- Tests/Functional/ContentTypes/TextElementTest.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/Functional/ContentTypes/BaseContentTypeTest.php b/Tests/Functional/ContentTypes/BaseContentTypeTest.php index aa5d025c..35a086a6 100644 --- a/Tests/Functional/ContentTypes/BaseContentTypeTest.php +++ b/Tests/Functional/ContentTypes/BaseContentTypeTest.php @@ -25,7 +25,7 @@ public function setUp(): void $this->importDataSet(__DIR__ . '/../Fixtures/content.xml'); } - protected function checkDefaultContentFields($contentElement, $id, $pid, $type, $colPos = 0, $categories = '') + protected function checkDefaultContentFields($contentElement, $id, $pid, $type, $colPos = 0, $categories = []) { self::assertEquals($id, $contentElement['id'], 'id mismatch'); self::assertEquals($type, $contentElement['type'], 'type mismatch'); diff --git a/Tests/Functional/ContentTypes/TextElementTest.php b/Tests/Functional/ContentTypes/TextElementTest.php index 654072b2..13ea87ad 100644 --- a/Tests/Functional/ContentTypes/TextElementTest.php +++ b/Tests/Functional/ContentTypes/TextElementTest.php @@ -26,8 +26,12 @@ public function testTextContentElement() $fullTree = json_decode((string)$response->getBody(), true); $contentElement = $fullTree['content']['colPos0'][0]; + $categories = [ + ['id' => 1, 'title' => 'SysCategory1Title'], + ['id' => 2, 'title' => 'SysCategory2Title'] + ]; - $this->checkDefaultContentFields($contentElement, 1, 1, 'text', 0, 'SysCategory1Title,SysCategory2Title'); + $this->checkDefaultContentFields($contentElement, 1, 1, 'text', 0, $categories); $this->checkAppearanceFields($contentElement, 'layout-1', 'Frame', 'SpaceBefore', 'SpaceAfter'); $this->checkHeaderFields($contentElement, 'Header', 'SubHeader', 1, 2); $this->checkHeaderFieldsLink($contentElement, 'Page 1', '/page1?parameter=999&cHash=', '_blank'); From d3ef16d996c3612bcba8d28b56b37492f65cc19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n?= Date: Mon, 2 Oct 2023 13:00:57 +0000 Subject: [PATCH 12/18] [TASK] Apply cs-fixer changes --- Tests/Functional/ContentTypes/TextElementTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/ContentTypes/TextElementTest.php b/Tests/Functional/ContentTypes/TextElementTest.php index 13ea87ad..87f5f5d9 100644 --- a/Tests/Functional/ContentTypes/TextElementTest.php +++ b/Tests/Functional/ContentTypes/TextElementTest.php @@ -28,7 +28,7 @@ public function testTextContentElement() $contentElement = $fullTree['content']['colPos0'][0]; $categories = [ ['id' => 1, 'title' => 'SysCategory1Title'], - ['id' => 2, 'title' => 'SysCategory2Title'] + ['id' => 2, 'title' => 'SysCategory2Title'], ]; $this->checkDefaultContentFields($contentElement, 1, 1, 'text', 0, $categories); From 9243fade8ded647979b04b20a33cc586900584f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n?= Date: Mon, 2 Oct 2023 13:03:02 +0000 Subject: [PATCH 13/18] [TASK] Update tests --- Tests/Functional/ContentTypes/ShortcutElementTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Tests/Functional/ContentTypes/ShortcutElementTest.php b/Tests/Functional/ContentTypes/ShortcutElementTest.php index 1197f237..3c65d51c 100644 --- a/Tests/Functional/ContentTypes/ShortcutElementTest.php +++ b/Tests/Functional/ContentTypes/ShortcutElementTest.php @@ -42,7 +42,12 @@ public function testShortcutContentElement() self::assertFalse(isset($contentElement['content']['shortcut'][0]['bodytext'])); // element at pos 1 is our TextElement - $this->checkDefaultContentFields($contentElement['content']['shortcut'][1], 1, 1, 'text', 0, 'SysCategory1Title,SysCategory2Title'); + $categories = [ + ['id' => 1, 'title' => 'SysCategory1Title'], + ['id' => 2, 'title' => 'SysCategory2Title'], + ]; + + $this->checkDefaultContentFields($contentElement['content']['shortcut'][1], 1, 1, 'text', 0, $categories); $this->checkAppearanceFields($contentElement['content']['shortcut'][1], 'layout-1', 'Frame', 'SpaceBefore', 'SpaceAfter'); $this->checkHeaderFields($contentElement['content']['shortcut'][1], 'Header', 'SubHeader', 1, 2); $this->checkHeaderFieldsLink($contentElement['content']['shortcut'][1], 'Page 1', '/page1?parameter=999&cHash=', '_blank'); From cf617975ef25f4a5ef3121d946645e258cd90b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Mon, 18 Dec 2023 17:00:21 +0100 Subject: [PATCH 14/18] [TASK] Ignore code coverage --- .../DataProcessing/CategoriesProcessor.php | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index e59f3f3f..73f6e404 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -15,33 +15,34 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; -/* +/** * Example usage (get categories by relation field): - categories = JSON - categories { - dataProcessing { - 10 = headless-categories - 10 { - relation.fieldName = categories - - as = categories - } - } - } + * categories = JSON + * categories { + * dataProcessing { + * 10 = headless-categories + * 10 { + * relation.fieldName = categories + * as = categories + * } + * } + * } * Example usage (get categories by comma-separated-list of category ids): - - categories = JSON - categories { - dataProcessing { - 10 = headless-categories - 10 { - categoryIdList = 1,3,5 - - as = categories - } - } - } - */ + * + * categories = JSON + * categories { + * dataProcessing { + * 10 = headless-categories + * 10 { + * categoryIdList = 1,3,5 + * + * as = categories + * } + * } + * } + * + * @codeCoverageIgnore + **/ class CategoriesProcessor implements DataProcessorInterface { From e1b338dea7b7d47c22a89ab0558f80f92cecfe03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Mon, 18 Dec 2023 17:03:54 +0100 Subject: [PATCH 15/18] [TASK] Fix code style --- Classes/DataProcessing/CategoriesProcessor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index 73f6e404..1a1f29ad 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -43,7 +43,6 @@ * * @codeCoverageIgnore **/ - class CategoriesProcessor implements DataProcessorInterface { /** From b82e3033a0e29a2c253fb9ad01653c70b73affa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Mon, 18 Dec 2023 17:08:34 +0100 Subject: [PATCH 16/18] [FEATURE] Make pidInList and recursive configurable --- Classes/DataProcessing/CategoriesProcessor.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index 1a1f29ad..6b0bc055 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -40,6 +40,21 @@ * } * } * } + * Example usage (get categories by comma-separated-list of category ids from custom pid): + * + * categories = JSON + * categories { + * dataProcessing { + * 10 = headless-categories + * 10 { + * categoryIdList = 1,3,5 + * pidInList = leveluid:0 + * recursive = 250 + * + * as = categories + * } + * } + * } * * @codeCoverageIgnore **/ @@ -66,7 +81,8 @@ public function process( } $defaultQueryConfig = [ - 'pidInList' => 'root', + 'pidInList' => (string)$cObj->stdWrapValue('pidInList', $processorConfiguration, 'root'), + 'recursive' => (string)$cObj->stdWrapValue('recursive', $processorConfiguration, '0'), 'selectFields' => '{#sys_category}.{#uid} AS id, {#sys_category}.{#title}', ]; $queryConfig = []; From 97bed4e1168ae78adb55c748f93e7c11c66c2512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Mon, 18 Dec 2023 17:13:19 +0100 Subject: [PATCH 17/18] [TASK] Rename categoryIdList with uidInList --- Classes/DataProcessing/CategoriesProcessor.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index 6b0bc055..5b063b63 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -34,7 +34,7 @@ * dataProcessing { * 10 = headless-categories * 10 { - * categoryIdList = 1,3,5 + * uidInList = 1,3,5 * * as = categories * } @@ -47,7 +47,7 @@ * dataProcessing { * 10 = headless-categories * 10 { - * categoryIdList = 1,3,5 + * uidInList = 1,3,5 * pidInList = leveluid:0 * recursive = 250 * @@ -87,10 +87,10 @@ public function process( ]; $queryConfig = []; - $categoryIdList = (string)$cObj->stdWrapValue('categoryIdList', $processorConfiguration, ''); - if (empty($categoryIdList) === false) { + $uidInList = (string)$cObj->stdWrapValue('uidInList', $processorConfiguration, ''); + if (empty($uidInList) === false) { $queryConfig = [ - 'where' => '{#sys_category.uid} IN (' . $categoryIdList . ')', + 'uidInList' => $uidInList, 'languageField' => 0, ]; } From 282c84b8c7d751e1d1d5f3cb6db9093f8326ef7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Schlosser?= Date: Mon, 18 Dec 2023 17:14:07 +0100 Subject: [PATCH 18/18] [TASK] Adjust code --- Classes/DataProcessing/CategoriesProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/DataProcessing/CategoriesProcessor.php b/Classes/DataProcessing/CategoriesProcessor.php index 5b063b63..c6662e5f 100644 --- a/Classes/DataProcessing/CategoriesProcessor.php +++ b/Classes/DataProcessing/CategoriesProcessor.php @@ -88,7 +88,7 @@ public function process( $queryConfig = []; $uidInList = (string)$cObj->stdWrapValue('uidInList', $processorConfiguration, ''); - if (empty($uidInList) === false) { + if (!empty($uidInList)) { $queryConfig = [ 'uidInList' => $uidInList, 'languageField' => 0,