andeancondor_74
Custom Action in the Resource Edit Page
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'; } }
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'; } }
4 replies