74 lines
2.8 KiB
JavaScript
74 lines
2.8 KiB
JavaScript
import { formBuilderPlugin } from '@payloadcms/plugin-form-builder';
|
|
/** REST/GraphQL: only logged-in users. Local API (submitForm) is unaffected. */ const submissionsCreateAccess = ({ req })=>Boolean(req.user);
|
|
/**
|
|
* Configures @payloadcms/plugin-form-builder from IPAL's FormsOption.
|
|
*
|
|
* Provides the forms / form-submissions collections and field types. E-mails
|
|
* after a submission are the form-builder's own (Forms → Emails), sent through
|
|
* the project's email adapter (mailAdapter()).
|
|
*
|
|
* SECURITY: form-builder defaults form-submissions to `create: () => true`, i.e.
|
|
* anyone can POST /api/form-submissions and skip everything submitForm enforces
|
|
* (rate limit, Turnstile, GDPR consent, schema validation). Here REST/GraphQL
|
|
* creation is limited to logged-in users; the site submits through submitForm
|
|
* (server action → Local API, which bypasses access by design). A project that
|
|
* really needs public REST submissions can override `formSubmissionOverrides.access.create`.
|
|
*/ export function buildFormsPlugin(forms) {
|
|
const adminGroup = forms.adminGroup === undefined ? 'Forms' : forms.adminGroup;
|
|
const group = adminGroup ? {
|
|
group: adminGroup
|
|
} : {};
|
|
return formBuilderPlugin({
|
|
fields: {
|
|
text: true,
|
|
textarea: true,
|
|
email: true,
|
|
number: true,
|
|
select: true,
|
|
checkbox: true,
|
|
message: true,
|
|
payment: false,
|
|
...forms.fields
|
|
},
|
|
...forms.redirectRelationships ? {
|
|
redirectRelationships: forms.redirectRelationships
|
|
} : {},
|
|
// Client-supplied collection overrides (e.g. a per-form notification
|
|
// address). The plugin provides the hook, not the opinion about which
|
|
// extra fields a form should carry.
|
|
// Tidy panel by default: both collections under one sidebar group with plain
|
|
// labels — no per-project overrides needed just to sort the sidebar.
|
|
formOverrides: {
|
|
labels: {
|
|
singular: 'Form',
|
|
plural: 'Forms'
|
|
},
|
|
...forms.formOverrides,
|
|
admin: {
|
|
...group,
|
|
...forms.formOverrides?.admin
|
|
}
|
|
},
|
|
formSubmissionOverrides: {
|
|
labels: {
|
|
singular: 'Submission',
|
|
plural: 'Submissions'
|
|
},
|
|
...forms.formSubmissionOverrides,
|
|
admin: {
|
|
...group,
|
|
defaultColumns: [
|
|
'form',
|
|
'createdAt'
|
|
],
|
|
...forms.formSubmissionOverrides?.admin
|
|
},
|
|
access: {
|
|
create: submissionsCreateAccess,
|
|
...forms.formSubmissionOverrides?.access
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
//# sourceMappingURL=formsPluginConfig.js.map
|