Skip to content

Commit 69e72f1

Browse files
committed
feat(laravel): add parent id and semantic id tracking to static blocks
1 parent 77ef74c commit 69e72f1

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

packages/laravel/src/View/NodeTransformers/Concerns/HandlesCraftileBlocks.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function compileBlock(string $type, string $id, string $propertiesExpr
4242

4343
$hash = hash('xxh128', $id);
4444
$idVar = '$__blockId'.$hash;
45+
$parentIdVar = '$__blockParentId'.$hash;
4546
$blockDataVar = '$__blockData'.$hash;
4647

4748
$compiler = app(BlockCompilerRegistry::class)->findCompiler($schema);
@@ -60,16 +61,17 @@ protected function compileBlock(string $type, string $id, string $propertiesExpr
6061
<?php
6162
if (isset(\$block)) {
6263
{$idVar} = craftile()->resolveStaticBlockId(\$block->id, '{$id}') ?? craftile()->generateChildId(\$block->id, '{$id}');
64+
{$parentIdVar} = \$block->id;
6365
} else {
6466
{$idVar} = '{$id}';
67+
{$parentIdVar} = null;
6568
}
6669
67-
{$blockDataVar} = BlockDatastore::getBlock({$idVar}, ['static' => true, 'repeated' => {$repeatedExpr}]);
70+
{$blockDataVar} = BlockDatastore::getBlock({$idVar}, ['parentId' => {$parentIdVar}, 'semanticId' => '{$id}', 'static' => true, 'repeated' => {$repeatedExpr}]);
6871
6972
if (!{$blockDataVar}) {
70-
{$blockDataVar} = craftile()->createBlockData(['id' => {$idVar}, 'type' => '{$type}', 'static' => true, 'repeated' => {$repeatedExpr}]);
73+
{$blockDataVar} = craftile()->createBlockData(['id' => {$idVar}, 'type' => '{$type}', 'parentId' => {$parentIdVar}, 'semanticId' => '{$id}', 'static' => true, 'repeated' => {$repeatedExpr}]);
7174
}
72-
7375
?>
7476
<?php if (craftile()->inPreview()) {
7577
craftile()->startBlock({$idVar}, $blockDataVar);

0 commit comments

Comments
 (0)