This repository was archived by the owner on Feb 14, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 22
33namespace CodeWithDennis \FilamentTests \Concerns \Resources ;
44
5+ use Filament \Actions \Action ;
6+ use Filament \Actions \ActionGroup ;
57use Filament \Resources \Pages \PageRegistration ;
68
79trait 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 )) {
You can’t perform that action at this time.
0 commit comments