array_map(fn (EmailTemplateSlot $slot): array => [ 'slot' => $slot->value, 'label' => $slot->label(), 'customized' => $this->resolver->resolve($slot) !== null, ], EmailTemplateSlot::cases()), ]); } public function edit(EmailTemplateSlot $slot): Response { $override = $this->resolver->resolve($slot); return Inertia::render('system/settings/email-templates/edit', [ 'slot' => $slot->value, 'label' => $slot->label(), 'subject' => $override['subject'] ?? $slot->defaultSubject(), 'body' => $override['body'] ?? $slot->defaultBody(), 'customized' => $override !== null, 'placeholders' => $slot->placeholders(), ]); } public function update(Request $request, EmailTemplateSlot $slot): RedirectResponse { $validated = $request->validate([ 'subject' => ['required', 'string', 'max:255'], 'body' => ['required', 'string', 'max:5000'], ]); EmailTemplate::query()->updateOrCreate(['slot' => $slot->value], $validated); $this->resolver->flush(); $this->activity->log(Action::SettingsUpdated, context: ['section' => 'email-template', 'slot' => $slot->value]); return back()->with('success', __('Email template saved.')); } public function destroy(EmailTemplateSlot $slot): RedirectResponse { EmailTemplate::query()->where('slot', $slot->value)->delete(); $this->resolver->flush(); $this->activity->log(Action::SettingsUpdated, context: ['section' => 'email-template-reset', 'slot' => $slot->value]); return back()->with('success', __('Email template reset to default.')); } /** * Renders this slot's *effective* email (the saved override if one * exists, otherwise the code default — toMail() resolves that itself * the same way a real send would) with representative sample content, * through the currently active email theme. Never sends anything. */ public function preview(EmailTemplateSlot $slot): HttpResponse { $notifiable = new User(['name' => 'Jane Client', 'email' => 'preview@example.com']); $mail = $this->sampleMail($slot, $notifiable); return new HttpResponse( $this->preview->render($mail, $this->emailTheme->currentThemeKey()), 200, ['Content-Type' => 'text/html; charset=UTF-8'], ); } private function sampleMail(EmailTemplateSlot $slot, User $notifiable): MailMessage { return match ($slot) { EmailTemplateSlot::FileShared => (new FileSharedNotification('sample-file.pdf', isFolder: false))->toMail($notifiable), EmailTemplateSlot::FolderShared => (new FileSharedNotification('Sample Folder', isFolder: true))->toMail($notifiable), EmailTemplateSlot::FileShareDigest => (new FileShareDigestNotification([ new PendingNotification(['subject_name' => 'sample-file.pdf', 'context' => ['is_folder' => false]]), new PendingNotification(['subject_name' => 'Sample Folder', 'context' => ['is_folder' => true]]), ]))->toMail($notifiable), EmailTemplateSlot::CommentPosted => (new CommentPostedNotification('sample-file.pdf', 'Jane Client', null))->toMail($notifiable), EmailTemplateSlot::CommentDigest => (new CommentDigestNotification([ new PendingNotification(['subject_name' => 'sample-file.pdf', 'context' => ['author_name' => 'Jane Client']]), new PendingNotification(['subject_name' => 'Brand Guidelines.pdf', 'context' => ['author_name' => 'Ada Admin']]), ]))->toMail($notifiable), EmailTemplateSlot::ClientAccountApproved => (new ClientAccountApprovedNotification)->toMail($notifiable), EmailTemplateSlot::ClientAccountDenied => (new ClientAccountDeniedNotification('Jane Client'))->toMail($notifiable), EmailTemplateSlot::ClientWelcome => (new ClientWelcomeNotification)->toMail($notifiable), EmailTemplateSlot::ClientInvited => (new ClientInvitationNotification('Jane Client', 'sample-token'))->toMail($notifiable), EmailTemplateSlot::ClientAccountEdited => (new ClientAccountEditedNotification)->toMail($notifiable), EmailTemplateSlot::AdminClientRegistered => (new AdminClientRegisteredNotification('Jane Client', 'preview@example.com', pendingApproval: false))->toMail($notifiable), EmailTemplateSlot::AdminClientUploaded => (new AdminClientUploadedNotification('Jane Client', 'sample-file.pdf', 0))->toMail($notifiable), EmailTemplateSlot::GroupMembershipRequested => (new GroupMembershipRequestedNotification('Jane Client', 'Sample Group'))->toMail($notifiable), EmailTemplateSlot::GroupMembershipApproved => (new GroupMembershipApprovedNotification('Sample Group'))->toMail($notifiable), EmailTemplateSlot::GroupMembershipDenied => (new GroupMembershipDeniedNotification('Sample Group'))->toMail($notifiable), EmailTemplateSlot::PasswordReset => (new ResetPasswordNotification('sample-token'))->toMail($notifiable), EmailTemplateSlot::TwoFactorReset => (new TwoFactorResetNotification)->toMail($notifiable), }; } }