Skip to content

Commit 45707d2

Browse files
author
merzilla
committed
[TASK] Make page fields to select configurable via configuration for TreeMenu
Add the possibility to provide a list of page fields to select for the TreeMenu by setting e.g.: pageFields = uid,pid,title,slug - If the property is not set, it uses "*" for the select fields. - If "*" is also in the list, it gets deleted from the list - empty values wil be removed, so a type like "uid,,pid,title" is covered The TreeMenu processor is a fast way to use it e.g. for an RESTful API. In order to create simpler API schemas it´s easier to define which fields are needed from pages. So the schema does not need to provide all ~100 fields if 5-6 are enough. The change does not touch that nav_title, hasSubpages and subpages will be populated.
1 parent 6479289 commit 45707d2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Classes/Domain/Repository/MenuRepository.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ public function getPageTree(int $startPageId, int $depth, array $configuration):
105105
return $page;
106106
}
107107

108+
protected function getPageFields(array $configuration): string
109+
{
110+
if (!empty($configuration['pageFields'])) {
111+
$items = GeneralUtility::trimExplode(',', $configuration['pageFields'], true);
112+
// just make sure if we have a field list to not have "*" included
113+
if (count($items) > 1 && ($key = array_search('*', $items)) !== false) {
114+
unset($items[$key]);
115+
}
116+
$pageFields = GeneralUtility::uniqueList(implode(',', $items));
117+
} else {
118+
$pageFields = '*';
119+
}
120+
return $pageFields;
121+
}
122+
108123
protected function getExcludeDoktypes(array $configuration): array
109124
{
110125
if (!empty($configuration['excludeDoktypes'])) {
@@ -137,10 +152,11 @@ public function getSubPagesOfPage(int $pageId, int $depth, array $configuration)
137152
$excludedPagesArray = GeneralUtility::intExplode(',', (string)$configuration['excludePages']);
138153
$whereClause .= ' AND uid NOT IN (' . implode(',', $excludedPagesArray) . ')';
139154
}
155+
$pageFields = $this->getPageFields($configuration);
140156
$excludedDoktypes = $this->getExcludeDoktypes($configuration);
141157
$pageTree = $this->pageRepository->getMenu(
142158
$pageId,
143-
'*',
159+
$pageFields,
144160
'sorting',
145161
'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ') ' . $whereClause,
146162
false

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Pure TypoScript-based solution:
7878
page.10.excludePages = 4,51
7979
# 0: default, 1 to include nav_hide = 1 pages
8080
page.10.includeNotInMenu = 0
81+
# if pageFields are not set, we take "*" from pages, but you can define
82+
page.10.pageFields = uid,pid,title,slug
8183
page.10.renderObj.level0 = TEXT
8284
page.10.renderObj.level0.typolink.parameter.data = field:uid
8385
page.10.renderObj.level0.typolink.ATagParams = class="active"
@@ -91,6 +93,7 @@ Fluid-based solution:
9193
page.10.dataProcessing.10.entryPoints = 23,13
9294
page.10.dataProcessing.10.depth = 3
9395
page.10.dataProcessing.10.excludePages = 4,51
96+
page.10.dataProcessing.10.pageFields = uid,pid,title,slug
9497
# 0: default, 1 to include nav_hide = 1 pages
9598
page.10.dataProcessing.10.includeNotInMenu = 0
9699
page.10.dataProcessing.10.as = mobilemenu

0 commit comments

Comments
 (0)