Skip to content

Commit 288c751

Browse files
authored
[BUGIFIX] Site set Settings: correct output (#709)
Correct output of default values and enums
1 parent b64bc44 commit 288c751

File tree

10 files changed

+493
-415
lines changed

10 files changed

+493
-415
lines changed

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,31 +182,65 @@ public function buildConfvalMenu(Directive $directive, array $settings): Confval
182182

183183

184184
/**
185-
* @param array<string, string> $setting
185+
* @param array<string, scalar|array<string, scalar>> $setting
186186
*/
187187
public function buildConfval(array $setting, string $idPrefix, string $key, Directive $directive): ConfvalNode
188188
{
189189
$content = [];
190-
if (($setting['description'] ?? '') !== '') {
190+
if (is_string($setting['description'] ?? false)) {
191191
$content[] = new ParagraphNode([
192192
new InlineCompoundNode([new PlainTextInlineNode((string)$setting['description'])]),
193193
]);
194194
}
195195
$default = null;
196196
if (($setting['default'] ?? '') !== '') {
197-
$default = new InlineCompoundNode([new CodeInlineNode((string)($setting['default'] ?? ''), '')]);
197+
$default = new InlineCompoundNode([new CodeInlineNode($this->customPrint(($setting['default'])), '')]);
198198
}
199+
$additionalFields = [];
200+
if (is_string($setting['label'] ?? false)) {
201+
$additionalFields['Label'] = new InlineCompoundNode([new PlainTextInlineNode($setting['label'] ?? '')]);
202+
}
203+
if (is_array($setting['enum'] ?? false)) {
204+
$additionalFields['Enum'] = new InlineCompoundNode([new PlainTextInlineNode((string) json_encode($setting['enum'], JSON_PRETTY_PRINT))]);
205+
}
206+
assert(is_scalar($setting['type']));
207+
199208
$confval = new ConfvalNode(
200209
$this->anchorNormalizer->reduceAnchor($idPrefix . $key),
201210
$key,
202211
new InlineCompoundNode([new CodeInlineNode((string)($setting['type'] ?? ''), '')]),
203212
false,
204213
$default,
205-
['Label' => new InlineCompoundNode([new PlainTextInlineNode($setting['label'] ?? '')])],
214+
$additionalFields,
206215
$content,
207216
$directive->getOptionBool('noindex'),
208217
);
209218
return $confval;
210219
}
211220

221+
private function customPrint(mixed $value): string
222+
{
223+
if (is_null($value)) {
224+
return 'null';
225+
}
226+
if (is_bool($value)) {
227+
return $value ? 'true' : 'false';
228+
}
229+
if (is_string($value)) {
230+
return sprintf('"%s"', $value);
231+
}
232+
if (is_float($value)) {
233+
return sprintf('%.2f', $value); // Adjust precision if needed
234+
}
235+
236+
if (is_int($value)) {
237+
return (string)$value;
238+
}
239+
if (is_array($value) || is_object($value)) {
240+
return (string)(json_encode($value, JSON_PRETTY_PRINT));
241+
}
242+
243+
return 'unkown'; // For other types or unexpected cases
244+
}
245+
212246
}

tests/Integration/tests/site-set-ext-syntax/expected/index.html

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,19 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
407407
data-bs-html="true">string</code>
408408
</dd>
409409
<dt class="field-odd">Default</dt>
410-
<dd class="field-odd"><code class="code-inline"
410+
<dd class="field-odd"><code class="code-inline code-inline-long"
411411
translate="no"
412412
aria-description=""
413413
aria-details=""
414-
data-bs-html="true">tt_content</code>
414+
data-bs-html="true">&quot;tt_content&quot;</code>
415415
</dd>
416416
<dt class="field-even">Label</dt>
417417
<dd class="field-even">List of accepted tables
418418
</dd>
419419
</dl>
420420
<div class="confval-description">
421421

422+
422423
</div>
423424
</dd>
424425
</dl>
@@ -444,14 +445,15 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
444445
translate="no"
445446
aria-description=""
446447
aria-details=""
447-
data-bs-html="true">a, abbr, acronym, address, article, aside, b, bdo, big, blockquote, br, caption, center, cite, code, col, colgroup, dd, del, dfn, dl, div, dt, em, figure, font, footer, header, h1, h2, h3, h4, h5, h6, hr, i, img, ins, kbd, label, li, link, meta, nav, ol, p, pre, q, s, samp, sdfield, section, small, span, strike, strong, style, sub, sup, table, thead, tbody, tfoot, td, th, tr, title, tt, u, ul, var</code>
448+
data-bs-html="true">&quot;a, abbr, acronym, address, article, aside, b, bdo, big, blockquote, br, caption, center, cite, code, col, colgroup, dd, del, dfn, dl, div, dt, em, figure, font, footer, header, h1, h2, h3, h4, h5, h6, hr, i, img, ins, kbd, label, li, link, meta, nav, ol, p, pre, q, s, samp, sdfield, section, small, span, strike, strong, style, sub, sup, table, thead, tbody, tfoot, td, th, tr, title, tt, u, ul, var&quot;</code>
448449
</dd>
449450
<dt class="field-even">Label</dt>
450451
<dd class="field-even">List of allowed HTML tags when rendering RTE content
451452
</dd>
452453
</dl>
453454
<div class="confval-description">
454455

456+
455457
</div>
456458
</dd>
457459
</dl>
@@ -477,11 +479,18 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
477479
translate="no"
478480
aria-description=""
479481
aria-details=""
480-
data-bs-html="true">lazy</code>
482+
data-bs-html="true">&quot;lazy&quot;</code>
481483
</dd>
482484
<dt class="field-even">Label</dt>
483485
<dd class="field-even">Default settings for browser-native image lazy loading
484486
</dd>
487+
<dt class="field-even">Enum</dt>
488+
<dd class="field-even">{
489+
&quot;lazy&quot;: &quot;Lazy&quot;,
490+
&quot;eager&quot;: &quot;Eager&quot;,
491+
&quot;auto&quot;: &quot;Auto&quot;
492+
}
493+
</dd>
485494
</dl>
486495
<div class="confval-description">
487496

@@ -510,6 +519,13 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
510519
<dt class="field-even">Label</dt>
511520
<dd class="field-even">Default settings for an image decoding hint to the browser
512521
</dd>
522+
<dt class="field-even">Enum</dt>
523+
<dd class="field-even">{
524+
&quot;sync&quot;: &quot;Sync&quot;,
525+
&quot;async&quot;: &quot;Asynchronous&quot;,
526+
&quot;auto&quot;: &quot;Auto&quot;
527+
}
528+
</dd>
513529
</dl>
514530
<div class="confval-description">
515531

@@ -715,7 +731,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
715731
translate="no"
716732
aria-description=""
717733
aria-details=""
718-
data-bs-html="true">#000000</code>
734+
data-bs-html="true">&quot;#000000&quot;</code>
719735
</dd>
720736
<dt class="field-even">Label</dt>
721737
<dd class="field-even">Media element border, color
@@ -820,7 +836,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
820836
translate="no"
821837
aria-description=""
822838
aria-details=""
823-
data-bs-html="true">800m</code>
839+
data-bs-html="true">&quot;800m&quot;</code>
824840
</dd>
825841
<dt class="field-even">Label</dt>
826842
<dd class="field-even">Click-enlarge Media Width
@@ -855,7 +871,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
855871
translate="no"
856872
aria-description=""
857873
aria-details=""
858-
data-bs-html="true">600m</code>
874+
data-bs-html="true">&quot;600m&quot;</code>
859875
</dd>
860876
<dt class="field-even">Label</dt>
861877
<dd class="field-even">Click-enlarge Media Height
@@ -890,7 +906,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
890906
translate="no"
891907
aria-description=""
892908
aria-details=""
893-
data-bs-html="true"></code>
909+
data-bs-html="true">false</code>
894910
</dd>
895911
<dt class="field-even">Label</dt>
896912
<dd class="field-even">Advanced, New window
@@ -925,7 +941,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
925941
translate="no"
926942
aria-description=""
927943
aria-details=""
928-
data-bs-html="true"></code>
944+
data-bs-html="true">false</code>
929945
</dd>
930946
<dt class="field-even">Label</dt>
931947
<dd class="field-even">Lightbox click-enlarge rendering
@@ -960,7 +976,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
960976
translate="no"
961977
aria-description=""
962978
aria-details=""
963-
data-bs-html="true">lightbox</code>
979+
data-bs-html="true">&quot;lightbox&quot;</code>
964980
</dd>
965981
<dt class="field-even">Label</dt>
966982
<dd class="field-even">Lightbox CSS class
@@ -995,7 +1011,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
9951011
translate="no"
9961012
aria-description=""
9971013
aria-details=""
998-
data-bs-html="true">lightbox[{field:uid}]</code>
1014+
data-bs-html="true">&quot;lightbox[{field:uid}]&quot;</code>
9991015
</dd>
10001016
<dt class="field-even">Label</dt>
10011017
<dd class="field-even">Lightbox rel=&quot;&quot; attribute
@@ -1030,14 +1046,15 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
10301046
translate="no"
10311047
aria-description=""
10321048
aria-details=""
1033-
data-bs-html="true">_blank</code>
1049+
data-bs-html="true">&quot;_blank&quot;</code>
10341050
</dd>
10351051
<dt class="field-even">Label</dt>
10361052
<dd class="field-even">Target for external links
10371053
</dd>
10381054
</dl>
10391055
<div class="confval-description">
10401056

1057+
10411058
</div>
10421059
</dd>
10431060
</dl>
@@ -1063,7 +1080,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
10631080
translate="no"
10641081
aria-description=""
10651082
aria-details=""
1066-
data-bs-html="true">path</code>
1083+
data-bs-html="true">&quot;path&quot;</code>
10671084
</dd>
10681085
<dt class="field-even">Label</dt>
10691086
<dd class="field-even">Parts to keep when building links
@@ -1099,6 +1116,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
10991116
</dl>
11001117
<div class="confval-description">
11011118

1119+
11021120
</div>
11031121
</dd>
11041122
</dl>
@@ -1125,6 +1143,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
11251143
</dl>
11261144
<div class="confval-description">
11271145

1146+
11281147
</div>
11291148
</dd>
11301149
</dl>
@@ -1151,6 +1170,7 @@ <h1>Site Set Configuration<a class="headerlink" href="#site-set-configuration" d
11511170
</dl>
11521171
<div class="confval-description">
11531172

1173+
11541174
</div>
11551175
</dd>
11561176
</dl>

0 commit comments

Comments
 (0)