Skip to content

Commit a09cdf4

Browse files
committed
fix: filled layouts with components
1 parent cb91b6d commit a09cdf4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Fields/Layouts.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use Illuminate\Contracts\View\View;
99
use Illuminate\Support\Collection;
1010
use MoonShine\AssetManager\Js;
11+
use MoonShine\Contracts\Core\HasComponentsContract;
1112
use MoonShine\Contracts\Core\PageContract;
1213
use MoonShine\Contracts\Core\ResourceContract;
1314
use MoonShine\Contracts\UI\ActionButtonContract;
15+
use MoonShine\Contracts\UI\Collection\ComponentsContract;
1416
use MoonShine\Contracts\UI\HasFieldsContract;
1517
use MoonShine\Layouts\Casts\LayoutItem;
1618
use MoonShine\Layouts\Casts\LayoutsCast;
@@ -169,9 +171,15 @@ public function getFilledLayouts(): LayoutCollection
169171
return LayoutCollection::make($filled);
170172
}
171173

172-
private function fillClonedRecursively(Collection $collection, mixed $data): Collection
174+
private function fillClonedRecursively(ComponentsContract|Collection $collection, mixed $data): Collection
173175
{
174176
return $collection->map(function (mixed $item) use ($data) {
177+
if ($item instanceof HasComponentsContract) {
178+
$item = (clone $item)->setComponents(
179+
$this->fillClonedRecursively($item->getComponents(), $data)->toArray()
180+
);
181+
}
182+
175183
if ($item instanceof HasFieldsContract) {
176184
$item = (clone $item)->fields(
177185
$this->fillClonedRecursively($item->getFields(), $data)->toArray()

0 commit comments

Comments
 (0)