Custom Action in the Resource Edit Page

I’m new to Filament but so impressed with what it can do. Working on an Application resource & need a custom action “Finalize Application” next to the Save changes button of the EditApplication page.
The experience is for the user to save draft changes with the normal EditAction button & use the custom action button when they are ready to finalize their application and be done making changes. In the Edit page I added the custom action under getFormActions() and for action() it calls a finalize method. I need to access the mutateFormDataBeforeSave() & getRedirectUrl() to change status and redirect to index when the custom action button is clicked. How do I do that and NOT trigger it when the normal Edit Action Save changes button is clicked?
2 Replies
Tieme
Tieme6mo ago
Can you share your code please? Because i think the following would be possible in you Edit Application resource page header actions
Action::make('finalize_application')
->requiresConfirmation()
->action(fn () => $this->post->finalize()),
Action::make('finalize_application')
->requiresConfirmation()
->action(fn () => $this->post->finalize()),
Header actions documentation : https://filamentphp.com/docs/3.x/panels/pages#header-actions
andeancondor_74
andeancondor_746mo ago
Thanks for your reply. Below is my code:
Essentially I want the mutateFormDataBeforeSave(), getRedirectUrl(). getSavedNotificationTitle() methods to run for the custom action finalize_application and NOT for the default EditAction Save changes: class EditApplication extends EditRecord { protected static string $resource = ApplicationResource::class; protected function getHeaderActions(): array { return [ Actions\DeleteAction::make(), ]; } protected function getFormActions(): array { return [ $this->getSaveFormAction(), Action::make('finalize_application') ->label('Finalize Application') ->color('success') ->visible(function ($record) { return $record->status === (Status::IN_PROGRESS); }) ->action('finalize'), ]; } public function finalize():void { $this->data['status'] = Status::IN_REVIEW; $this->getRecord()->update($this->data); } protected function mutateFormDataBeforeSave(array $data): array { $data['accept_admission_deadline'] = Application::getAcceptAdmissionDeadline(); return $data; } protected function getRedirectUrl(): string { return $this->getResource()::getUrl('index'); } protected function getSavedNotificationTitle(): ?string { return 'Application updated'; } }