Skip to content

Commit

Permalink
fix: filled layouts with components
Browse files Browse the repository at this point in the history
  • Loading branch information
DissNik committed Oct 30, 2024
1 parent cb91b6d commit a09cdf4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Fields/Layouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a09cdf4

Please sign in to comment.