Skip to content

Commit 15c2c0e

Browse files
authored
[TASK] Display site setting categories (#774)
1 parent 6d23c2a commit 15c2c0e

File tree

10 files changed

+2525
-398
lines changed

10 files changed

+2525
-398
lines changed

packages/typo3-docs-theme/src/Directives/SiteSetSettingsDirective.php

Lines changed: 96 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ final class SiteSetSettingsDirective extends BaseDirective
3636
{
3737
public const NAME = 'typo3:site-set-settings';
3838
public const FACET = 'Site Setting';
39+
public const CATEGORY_FACET = 'Site Setting Category';
3940

4041
public function __construct(
4142
private readonly LoggerInterface $logger,
@@ -194,18 +195,21 @@ public function buildConfvalMenu(Directive $directive, array $settings, array $c
194195
if ($directive->getOptionString('name') !== '') {
195196
$idPrefix = $directive->getOptionString('name') . '-';
196197
}
197-
$categoryArray = [];
198-
foreach ($categories as $key => $category) {
199-
$categoryArray[$key] = [
200-
'label' => $category['label'] ?? $categoryLabels[$key] ?? '',
201-
'parent' => $category['parent'] ?? '',
202-
];
198+
$categoryArray = $this->buildCategoryArray($categories, $categoryLabels);
199+
$rootCategories = [];
200+
foreach ($categoryArray as $key => $category) {
201+
if (isset($categoryArray[$category['parent']])) {
202+
assert(is_array($categoryArray[$category['parent']]['children']));
203+
$categoryArray[$category['parent']]['children'][] = &$categoryArray[$key];
204+
} else {
205+
$rootCategories[] = &$categoryArray[$key];
206+
}
203207
}
204-
205-
$confvals = [];
206208
foreach ($settings as $key => $setting) {
207-
$confvals[] = $this->buildConfval($setting, $idPrefix, $key, $directive, $labels, $descriptions, $categoryArray);
209+
$confval = $this->buildConfval($setting, $idPrefix, $key, $directive, $labels, $descriptions, $categoryArray);
210+
$this->assignConfvalsToCategories($setting['category'] ?? '', $categoryArray, $confval, $rootCategories);
208211
}
212+
$confvals = $this->buildCategoryConfvals($rootCategories, $idPrefix, $directive);
209213
$reservedParameterNames = [
210214
'name',
211215
'class',
@@ -335,4 +339,87 @@ private function getCategoryRootline(array $categoryArray, string $key): string
335339
return $this->getCategoryRootline($categoryArray, $parent) . ' > ' . $label;
336340
}
337341

342+
/**
343+
* @param array<string, array<string, mixed>> $categories
344+
* @param array<string, string> $categoryLabels
345+
* @return array<string, array<string, mixed>>
346+
*/
347+
public function buildCategoryArray(array $categories, array $categoryLabels): array
348+
{
349+
$categoryArray = [];
350+
foreach ($categories as $key => $category) {
351+
$categoryArray[$key] = [
352+
'label' => $category['label'] ?? $categoryLabels[$key] ?? '',
353+
'parent' => $category['parent'] ?? '',
354+
'key' => $key,
355+
'confvals' => [],
356+
'children' => [],
357+
];
358+
}
359+
return $categoryArray;
360+
}
361+
362+
/**
363+
* @param array<string, array<string, mixed>> $categoryArray
364+
* @param array<array<string, mixed>> $rootCategories
365+
*/
366+
public function assignConfvalsToCategories(string $category, array &$categoryArray, ConfvalNode $confval, array &$rootCategories): void
367+
{
368+
if (is_array($categoryArray[$category]['confvals'] ?? false)) {
369+
$categoryArray[$category]['confvals'][] = $confval;
370+
} else {
371+
$categoryArray[$category] = [
372+
'label' => '',
373+
'parent' => '',
374+
'key' => $category,
375+
'children' => [],
376+
'confvals' => [$confval],
377+
];
378+
$rootCategories[] = &$categoryArray[$category];
379+
}
380+
}
381+
382+
/**
383+
* @param array<array<string, mixed>> $categories
384+
* @return ConfvalNode[]
385+
*/
386+
private function buildCategoryConfvals(array $categories, string $idPrefix, Directive $directive): array
387+
{
388+
if ($categories === []) {
389+
return [];
390+
}
391+
$confvals = [];
392+
foreach ($categories as $category) {
393+
$children = [];
394+
if (is_array($category['children'] ?? false)) {
395+
$children = $this->buildCategoryConfvals($category['children'], $idPrefix, $directive);
396+
}
397+
$key = $category['key'];
398+
if ($key === '') {
399+
$key = '_global';
400+
}
401+
assert(is_string($key));
402+
$additionalFields = [];
403+
$additionalFields['searchFacet'] = new InlineCompoundNode([new PlainTextInlineNode(self::CATEGORY_FACET)]);
404+
405+
$label = $category['label'];
406+
if ($label !== '') {
407+
assert(is_string($label));
408+
$additionalFields['Label'] = new InlineCompoundNode([new PlainTextInlineNode($label)]);
409+
}
410+
assert(is_array($category['confvals']));
411+
$confvals[] = new ConfvalNode(
412+
$this->anchorNormalizer->reduceAnchor($idPrefix . 'category-' . $key),
413+
$key,
414+
null,
415+
false,
416+
null,
417+
$additionalFields,
418+
array_merge($children, $category['confvals']),
419+
$directive->getOptionBool('noindex'),
420+
);
421+
}
422+
return $confvals;
423+
}
424+
338425
}

tests/Integration/tests/roles/role-composer/expected/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h1>Document Title<a class="headerlink" href="#document-title" data-bs-toggle="m
1313
data-homepage="https://typo3.org/"
1414
data-documentation=""
1515
data-issues="https://github.com/TYPO3/testing-framework/issues"
16-
data-source="https://github.com/TYPO3/testing-framework/tree/8.2.1"
16+
data-source="https://github.com/TYPO3/testing-framework/tree/8.2.2"
1717
>
1818
typo3/testing-framework
1919
</a> to test projects based on

0 commit comments

Comments
 (0)