Skip to content
This repository was archived by the owner on Feb 14, 2026. It is now read-only.

Commit b5c78db

Browse files
Add method to retrieve page header actions
1 parent f4a62e3 commit b5c78db

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Concerns/Resources/InteractsWithPages.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace CodeWithDennis\FilamentTests\Concerns\Resources;
44

5+
use Filament\Actions\Action;
6+
use Filament\Actions\ActionGroup;
57
use Filament\Resources\Pages\PageRegistration;
68

79
trait InteractsWithPages
@@ -28,6 +30,35 @@ public function hasPage(string $page): bool
2830
return $this->hasPages([$page]);
2931
}
3032

33+
public function getPageHeaderAction(string $page, string $action)
34+
{
35+
return collect($this->getPageHeaderActions($page))
36+
->first(fn (Action $flatAction): bool => $flatAction->getName() === $action);
37+
}
38+
39+
public function getPageHeaderActions(string $page): array
40+
{
41+
$page = $this->getPage($page)->getPage();
42+
$reflection = new \ReflectionClass($page);
43+
$method = $reflection->getMethod('getHeaderActions');
44+
45+
$method->setAccessible(true);
46+
47+
$actions = $method->invoke(app($page));
48+
$flatActions = [];
49+
50+
/* We need to flatten the actions because they can be grouped inside ActionGroup */
51+
foreach ($actions as $action) {
52+
if ($action instanceof Action) {
53+
$flatActions[] = $action;
54+
} elseif ($action instanceof ActionGroup) {
55+
$flatActions = [...$flatActions, ...$action->getActions()];
56+
}
57+
}
58+
59+
return $flatActions;
60+
}
61+
3162
public function getPageClass(string $page): ?string
3263
{
3364
if (! $this->hasPage($page)) {

0 commit comments

Comments
 (0)