Skip to content

Commit

Permalink
🩹 Fix innerBlocks template handling (Fixes #269)
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Jul 19, 2024
1 parent 8d08e3d commit d650e16
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,18 +414,20 @@ public function handleTemplate(array $template = []): Collection
{
return collect($template)->map(function ($block, $key) {
$name = is_numeric($key)
? (is_string($block) ? $block : array_key_first($block))
? array_key_first((array) $block)
: $key;

$value = is_numeric($key)
? (is_string($block) ? [] : $block[$name])
? ($block[$name] ?? [])
: $block;

$value = is_array($value) && Arr::has($value, 'innerBlocks')
? array_merge($value, [
'innerBlocks' => $this->handleTemplate($value['innerBlocks'])->all(),
])
: $value;
if (is_array($value) && isset($value['innerBlocks'])) {
$innerBlocks = $this->handleTemplate($value['innerBlocks'])->all();

unset($value['innerBlocks']);

return [$name, $value, $innerBlocks];
}

return [$name, $value];
})->values();
Expand Down

0 comments on commit d650e16

Please sign in to comment.