diff --git a/packages/infolists/src/Concerns/InteractsWithInfolists.php b/packages/infolists/src/Concerns/InteractsWithInfolists.php index a907b69312e..67ee2e81632 100644 --- a/packages/infolists/src/Concerns/InteractsWithInfolists.php +++ b/packages/infolists/src/Concerns/InteractsWithInfolists.php @@ -40,6 +40,8 @@ trait InteractsWithInfolists public ?string $mountedInfolistActionsInfolist = null; + public ?array $mountedInfolistActionsArguments = []; + public function getInfolist(string $name): ?Infolist { $infolist = $this->getCachedInfolists()[$name] ?? null; @@ -165,9 +167,10 @@ public function callMountedInfolistAction(array $arguments = []): mixed return $result; } - public function mountInfolistAction(string $name, ?string $component = null, ?string $infolist = null): mixed + public function mountInfolistAction(string $name, ?string $component = null, ?string $infolist = null, array $arguments = []): mixed { $this->mountedInfolistActions[] = $name; + $this->mountedInfolistActionsArguments[] = $arguments; $this->mountedInfolistActionsData[] = []; if (blank($this->mountedInfolistActionsComponent) && filled($component)) { @@ -258,11 +261,13 @@ public function mountedInfolistActionHasForm(?Action $mountedAction = null): boo public function getMountedInfolistAction(): ?Action { + $actionNestingIndex ??= array_key_last($this->mountedInfolistActions); + if (! count($this->mountedInfolistActions ?? [])) { return null; } - return $this->getMountedInfolistActionComponent()?->getAction($this->mountedInfolistActions); + return $this->getMountedInfolistActionComponent()?->getAction($this->mountedInfolistActions)?->arguments($this->mountedInfolistActionsArguments[$actionNestingIndex] ?? []); } public function getMountedInfolistActionComponent(): ?Component @@ -301,8 +306,7 @@ public function unmountInfolistAction(bool $shouldCancelParentActions = true, bo $action = $this->getMountedInfolistAction(); if (! ($shouldCancelParentActions && $action)) { - array_pop($this->mountedInfolistActions); - array_pop($this->mountedInfolistActionsData); + $this->popMountedInfolistAction(); } elseif ($action->shouldCancelAllParentActions()) { $this->mountedInfolistActions = []; $this->mountedInfolistActionsData = []; @@ -310,8 +314,7 @@ public function unmountInfolistAction(bool $shouldCancelParentActions = true, bo $parentActionToCancelTo = $action->getParentActionToCancelTo(); while (true) { - $recentlyClosedParentAction = array_pop($this->mountedInfolistActions); - array_pop($this->mountedInfolistActionsData); + $recentlyClosedParentAction = $this->popMountedInfolistAction(); if ( blank($parentActionToCancelTo) || @@ -343,6 +346,17 @@ public function unmountInfolistAction(bool $shouldCancelParentActions = true, bo $this->openInfolistActionModal(); } + protected function popMountedInfolistAction(): ?string + { + try { + return array_pop($this->mountedInfolistActions); + } finally { + array_pop($this->mountedInfolistActionsArguments); + array_pop($this->mountedInfolistActions); + array_pop($this->mountedInfolistActionsData); + } + } + protected function makeInfolist(): Infolist { return Infolist::make($this);