Skip to content

Commit

Permalink
Fix TableOfContents block with invalid depth
Browse files Browse the repository at this point in the history
(fix #2145)
  • Loading branch information
zerocrates committed Feb 27, 2024
1 parent 112a8ab commit 42281d1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions application/src/Site/BlockLayout/TableOfContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ public function form(PhpRenderer $view, SiteRepresentation $site,
) {
$depth = new Number("o:block[__blockIndex__][o:data][depth]");

$depth->setValue($block ? $block->dataValue('depth', 1) : 1);
$depthValue = 1;
if ($block) {
$blockDepth = (int) $block->dataValue('depth');
if ($blockDepth > 1) {
$depthValue = $blockDepth;
}
}
$depth->setValue($depthValue);
$depth->setAttribute('min', 1);

$html = '';
Expand Down Expand Up @@ -53,7 +60,11 @@ public function render(PhpRenderer $view, SitePageBlockRepresentation $block, $t
}
$subNav = new Navigation($newPages);

$depth = $block->dataValue('depth', 1);
// Don't use dataValue's default here; we need to handle empty/non-numerics anyway
$depth = (int) $block->dataValue('depth');
if ($depth < 1) {
$depth = 1;
}

return $view->partial($templateViewScript, [
'block' => $block,
Expand Down

0 comments on commit 42281d1

Please sign in to comment.