From a09cdf4d4495de1c4929c62be2e764f8d53b47c0 Mon Sep 17 00:00:00 2001 From: Alexander Nikushkin Date: Wed, 30 Oct 2024 11:22:50 +0500 Subject: [PATCH] fix: filled layouts with components --- src/Fields/Layouts.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Fields/Layouts.php b/src/Fields/Layouts.php index d23303e..7580888 100644 --- a/src/Fields/Layouts.php +++ b/src/Fields/Layouts.php @@ -8,9 +8,11 @@ use Illuminate\Contracts\View\View; use Illuminate\Support\Collection; use MoonShine\AssetManager\Js; +use MoonShine\Contracts\Core\HasComponentsContract; use MoonShine\Contracts\Core\PageContract; use MoonShine\Contracts\Core\ResourceContract; use MoonShine\Contracts\UI\ActionButtonContract; +use MoonShine\Contracts\UI\Collection\ComponentsContract; use MoonShine\Contracts\UI\HasFieldsContract; use MoonShine\Layouts\Casts\LayoutItem; use MoonShine\Layouts\Casts\LayoutsCast; @@ -169,9 +171,15 @@ public function getFilledLayouts(): LayoutCollection return LayoutCollection::make($filled); } - private function fillClonedRecursively(Collection $collection, mixed $data): Collection + private function fillClonedRecursively(ComponentsContract|Collection $collection, mixed $data): Collection { return $collection->map(function (mixed $item) use ($data) { + if ($item instanceof HasComponentsContract) { + $item = (clone $item)->setComponents( + $this->fillClonedRecursively($item->getComponents(), $data)->toArray() + ); + } + if ($item instanceof HasFieldsContract) { $item = (clone $item)->fields( $this->fillClonedRecursively($item->getFields(), $data)->toArray()