Readable form emails (forms.emailLayout)
{{*:table}} renders a readable submission summary (questions, option labels,
grouped by step, empty fields skipped) inside an email template with logo,
accent colour and footer from Site Settings → Emails. submitForm stores the
submission in the page language, so emails follow the visitor's locale.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { BeforeEmail } from '@payloadcms/plugin-form-builder/types'
|
||||
import type { Block, Field, Plugin } from 'payload'
|
||||
|
||||
import { fields as builtinBlocks, formBuilderPlugin } from '@payloadcms/plugin-form-builder'
|
||||
@@ -6,6 +7,7 @@ import type { FormsOption } from './types.js'
|
||||
|
||||
import { hasMinimumRole, isAdmin } from '../access/predicates.js'
|
||||
import { checkboxGroupBlock, stepBlock, withShowWhen } from './builderBlocks.js'
|
||||
import { buildEmailLayoutHook } from './emailLayout.js'
|
||||
|
||||
type AccessArgs = { req: { user?: unknown } }
|
||||
|
||||
@@ -56,7 +58,16 @@ function hideEmails(fields: Field[]): Field[] {
|
||||
export function buildFormsPlugin(forms: FormsOption): Plugin {
|
||||
const adminGroup = forms.adminGroup === undefined ? 'Forms' : forms.adminGroup
|
||||
const group = adminGroup ? { group: adminGroup } : {}
|
||||
const layout = forms.emailLayout ? buildEmailLayoutHook({ formsSlug: forms.formOverrides?.slug ?? 'forms' }) : undefined
|
||||
const beforeEmail: BeforeEmail | undefined =
|
||||
layout || forms.beforeEmail
|
||||
? async (emails, args) => {
|
||||
const laidOut = layout ? await layout(emails, args) : emails
|
||||
return forms.beforeEmail ? forms.beforeEmail(laidOut, args) : laidOut
|
||||
}
|
||||
: undefined
|
||||
return formBuilderPlugin({
|
||||
...(beforeEmail ? { beforeEmail } : {}),
|
||||
// Built-in types + ipal's `step` and `checkboxGroup` (builderBlocks). All are
|
||||
// panel choices only — a form uses what the editor adds, nothing changes on
|
||||
// existing forms. Switch any off with forms.fields.<type>: false.
|
||||
|
||||
Reference in New Issue
Block a user