@@ -76,75 +76,101 @@ protected function cacheActions(): void
7676
7777 public function getActions (): array
7878 {
79- return collect ($ this ->resources )->transform (function ($ resource ) {
80- $ r = App::make ($ resource ['resource_name ' ]);
81-
82- return CreateAction::make ($ resource ['action_name ' ])
83- ->authorize ($ r ::canCreate ())
84- ->model ($ resource ['model ' ])
85- ->slideOver (fn (): bool => QuickCreatePlugin::get ()->shouldUseSlideOver ())
86- ->form (function ($ arguments , $ form ) use ($ r ) {
87- return $ r ->form ($ form ->operation ('create ' )->columns ());
88- })->action (function (array $ arguments , Form $ form , CreateAction $ action ) use ($ r ): void {
89- $ model = $ action ->getModel ();
90-
91- $ record = $ action ->process (function (array $ data , HasActions $ livewire ) use ($ model , $ action , $ r ): Model {
92- if ($ translatableContentDriver = $ livewire ->makeFilamentTranslatableContentDriver ()) {
93- $ record = $ translatableContentDriver ->makeRecord ($ model , $ data );
94- } else {
95- $ record = new $ model ();
96- $ record ->fill ($ data );
79+ return collect ($ this ->resources )
80+ ->transform (function ($ resource ) {
81+ $ r = App::make ($ resource ['resource_name ' ]);
82+ $ canCreateAnother = QuickCreatePlugin::get ()->canCreateAnother ();
83+
84+ if ($ canCreateAnother === null ) {
85+ if ($ r ->hasPage ('create ' )) {
86+ $ canCreateAnother = App::make ($ r ->getPages ()['create ' ]->getPage ())::canCreateAnother ();
87+ } else {
88+ $ page = isset ($ r ->getPages ()['index ' ])
89+ ? $ r ->getPages ()['index ' ]->getPage ()
90+ : null ;
91+
92+ if ($ page ) {
93+ $ reflectionMethod = new \ReflectionMethod ($ page , 'getHeaderActions ' );
94+ $ actions = $ reflectionMethod ->invoke (new $ page ());
95+ $ createAction = collect ($ actions )->filter (function ($ action ) {
96+ return $ action instanceof CreateAction;
97+ })->first ();
98+
99+ if ($ createAction ) {
100+ $ canCreateAnother = $ createAction ->canCreateAnother ();
101+ }
97102 }
103+ }
104+ }
105+
106+ return CreateAction::make ($ resource ['action_name ' ])
107+ ->authorize ($ r ::canCreate ())
108+ ->model ($ resource ['model ' ])
109+ ->slideOver (fn (): bool => QuickCreatePlugin::get ()->shouldUseSlideOver ())
110+ ->form (function ($ arguments , $ form ) use ($ r ) {
111+ return $ r ->form ($ form ->operation ('create ' )->columns ());
112+ })
113+ ->createAnother ($ canCreateAnother )
114+ ->action (function (array $ arguments , Form $ form , CreateAction $ action ) use ($ r ): void {
115+ $ model = $ action ->getModel ();
116+
117+ $ record = $ action ->process (function (array $ data , HasActions $ livewire ) use ($ model , $ action , $ r ): Model {
118+ if ($ translatableContentDriver = $ livewire ->makeFilamentTranslatableContentDriver ()) {
119+ $ record = $ translatableContentDriver ->makeRecord ($ model , $ data );
120+ } else {
121+ $ record = new $ model ();
122+ $ record ->fill ($ data );
123+ }
98124
99- if ($ relationship = $ action ->getRelationship ()) {
100- /** @phpstan-ignore-next-line */
101- $ relationship ->save ($ record );
125+ if ($ relationship = $ action ->getRelationship ()) {
126+ /** @phpstan-ignore-next-line */
127+ $ relationship ->save ($ record );
102128
103- return $ record ;
104- }
129+ return $ record ;
130+ }
105131
106- if (
107- $ r ::isScopedToTenant () &&
108- ($ tenant = Filament::getTenant ())
109- ) {
110- $ relationship = $ r ::getTenantRelationship ($ tenant );
132+ if (
133+ $ r ::isScopedToTenant () &&
134+ ($ tenant = Filament::getTenant ())
135+ ) {
136+ $ relationship = $ r ::getTenantRelationship ($ tenant );
111137
112- if ($ relationship instanceof HasManyThrough) {
113- $ record ->save ();
138+ if ($ relationship instanceof HasManyThrough) {
139+ $ record ->save ();
114140
115- return $ record ;
116- }
141+ return $ record ;
142+ }
117143
118- return $ relationship ->save ($ record );
119- }
144+ return $ relationship ->save ($ record );
145+ }
120146
121- $ record ->save ();
147+ $ record ->save ();
122148
123- return $ record ;
124- });
149+ return $ record ;
150+ });
125151
126- $ action ->record ($ record );
127- $ form ->model ($ record )->saveRelationships ();
152+ $ action ->record ($ record );
153+ $ form ->model ($ record )->saveRelationships ();
128154
129- if ($ arguments ['another ' ] ?? false ) {
130- $ action ->callAfter ();
131- $ action ->sendSuccessNotification ();
155+ if ($ arguments ['another ' ] ?? false ) {
156+ $ action ->callAfter ();
157+ $ action ->sendSuccessNotification ();
132158
133- $ action ->record (null );
159+ $ action ->record (null );
134160
135- // Ensure that the form record is anonymized so that relationships aren't loaded.
136- $ form ->model ($ model );
161+ // Ensure that the form record is anonymized so that relationships aren't loaded.
162+ $ form ->model ($ model );
137163
138- $ form ->fill ();
164+ $ form ->fill ();
139165
140- $ action ->halt ();
166+ $ action ->halt ();
141167
142- return ;
143- }
168+ return ;
169+ }
144170
145- $ action ->success ();
146- });
147- })
171+ $ action ->success ();
172+ });
173+ })
148174 ->values ()
149175 ->toArray ();
150176 }
0 commit comments