1313
1414trait HasActions
1515{
16+ /**
17+ * @var array<string, Action>
18+ */
1619 protected array $ cachedTreeToolbarActions = [];
1720
21+ /**
22+ * @var array<string, Action>
23+ */
1824 protected array $ cachedTreeActions = [];
1925
20- protected function resolveAction (array $ action , array $ parentActions ): ?FilamentActionsAction
21- {
22- if ($ this instanceof HasTree) {
23-
24- $ resolvedAction = null ;
25-
26- if (
27- filled ($ action ['context ' ]['tree ' ] ?? null ) ||
28- filled ($ action ['arguments ' ]['treeToolbar ' ] ?? null )
29- ) {
30-
31- if (! isset ($ action ['name ' ]) || empty ($ action ['name ' ])) {
32- throw new ActionNotResolvableException ('Action name is not specified. ' );
33- }
34-
35- if (($ action ['arguments ' ]['treeToolbar ' ] ?? false ) === true ) {
36- $ resolvedAction = $ this ->cachedTreeToolbarActions [$ action ['name ' ]] ?? null ;
37- } else {
38- $ resolvedAction = $ this ->cachedTreeActions [$ action ['name ' ]] ?? null ;
39- }
40-
41- if ($ resolvedAction ) {
42-
43- if (filled ($ action ['context ' ]['recordKey ' ] ?? null )) {
44- $ record = $ this ->getTreeRecord ($ action ['context ' ]['recordKey ' ]);
45-
46- $ resolvedAction ->getRootGroup ()?->record($ record ) ?? $ resolvedAction ->record ($ record );
47- }
48-
49- return $ resolvedAction ;
50- }
51- }
52-
53- }
54-
55- return parent ::resolveAction ($ action , $ parentActions );
56- }
57-
58- public function cacheTreeActions (): void
26+ public function cacheHasActions (): void
5927 {
6028 $ this ->cachedTreeActions = [];
6129 $ this ->cachedTreeToolbarActions = [];
@@ -94,11 +62,10 @@ public function cacheTreeActions(): void
9462 return [$ action ];
9563 })
9664 // Configure action
97- ->map (fn (Action |FilamentActionsAction $ action ) => $ action ->configureUsing (
98- Closure::fromCallable ([$ this , 'configureTreeAction ' ]),
99- fn () => $ action ->configure (),
100- )
101- )
65+ ->map (function ($ action ) {
66+ $ this ->configureTreeAction ($ action );
67+ return $ action ;
68+ })
10269 // Key by action name (resolve used)
10370 ->mapWithKeys (fn (Action |FilamentActionsAction $ action ) => [
10471 $ action ->getName () => $ configureResolvedAction ($ action ),
@@ -111,6 +78,44 @@ public function cacheTreeActions(): void
11178
11279 }
11380
81+ protected function resolveAction (array $ action , array $ parentActions ): ?FilamentActionsAction
82+ {
83+ if ($ this instanceof HasTree) {
84+
85+ $ resolvedAction = null ;
86+
87+ if (
88+ filled ($ action ['context ' ]['tree ' ] ?? null ) ||
89+ filled ($ action ['arguments ' ]['treeToolbar ' ] ?? null )
90+ ) {
91+
92+ if (! isset ($ action ['name ' ]) || empty ($ action ['name ' ])) {
93+ throw new ActionNotResolvableException ('Action name is not specified. ' );
94+ }
95+
96+ if (($ action ['arguments ' ]['treeToolbar ' ] ?? false ) === true ) {
97+ $ resolvedAction = $ this ->cachedTreeToolbarActions [$ action ['name ' ]] ?? null ;
98+ } else {
99+ $ resolvedAction = $ this ->cachedTreeActions [$ action ['name ' ]] ?? null ;
100+ }
101+
102+ if ($ resolvedAction ) {
103+
104+ if (filled ($ action ['context ' ]['recordKey ' ] ?? null )) {
105+ $ record = $ this ->getTreeRecord ($ action ['context ' ]['recordKey ' ]);
106+
107+ $ resolvedAction ->getRootGroup ()?->record($ record ) ?? $ resolvedAction ->record ($ record );
108+ }
109+
110+ return $ resolvedAction ;
111+ }
112+ }
113+
114+ }
115+
116+ return parent ::resolveAction ($ action , $ parentActions );
117+ }
118+
114119 protected function configureTreeAction (Action |FilamentActionsAction $ action ): void {}
115120
116121 /**
0 commit comments