enabled: false keeps the plugin's schema, drops only its behaviour
Returning the incoming config dropped the plugin's collections and globals,
so a Postgres migration would drop their tables. Now collections, globals
and fields stay; endpoints, onInit and admin components are left out.
Also: ipalKit({ forms: { consentFieldName } }) is stored in config.custom.ipal.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a87742621a
commit
38c1d9215e
+20
-3
@@ -5,10 +5,10 @@ import type { IpalOptions, TotpPluginFactory } from './types.js'
|
||||
import { buildCookieSettings } from './globals/CookieSettings/index.js'
|
||||
import { migrateCookieSettingsSaveButton } from './globals/CookieSettings/migrateSaveButton.js'
|
||||
import { buildNotifications } from './globals/Notifications/index.js'
|
||||
import { applyGlobalOverrides } from './globals/overrides.js'
|
||||
import { buildSiteIntegrations } from './globals/SiteIntegrations/index.js'
|
||||
import { buildSiteSettings } from './globals/SiteSettings/index.js'
|
||||
import { adminOnly, adminOrSelf, injectRoles } from './modules/access/index.js'
|
||||
import { applyGlobalOverrides } from './globals/overrides.js'
|
||||
import { buildConsentLogCollection, buildConsentLogEndpoint } from './modules/consent/consentLog.js'
|
||||
import { buildConstructionFields } from './modules/construction/fields.js'
|
||||
import { buildArchiveFields } from './modules/content/index.js'
|
||||
@@ -50,10 +50,23 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
validateI18nConfig(options.i18n)
|
||||
|
||||
return async (incomingConfig: Config): Promise<Config> => {
|
||||
// Early return when disabled — schema stays, behavior off
|
||||
const config = await transform(incomingConfig)
|
||||
// Disabled: schema stays (collections, globals, fields — so a Postgres
|
||||
// migration doesn't drop the plugin's tables), behaviour goes: no plugin
|
||||
// endpoints, onInit work or admin components. Returning the incoming
|
||||
// config untouched used to drop the plugin's collections and globals.
|
||||
if (options.enabled === false) {
|
||||
return incomingConfig
|
||||
return {
|
||||
...config,
|
||||
admin: { ...config.admin, components: incomingConfig.admin?.components },
|
||||
endpoints: incomingConfig.endpoints,
|
||||
onInit: incomingConfig.onInit,
|
||||
}
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
async function transform(incomingConfig: Config): Promise<Config> {
|
||||
|
||||
let config = { ...incomingConfig }
|
||||
|
||||
@@ -246,6 +259,10 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
// --- forms: apply @payloadcms/plugin-form-builder directly ---
|
||||
if (options.forms) {
|
||||
config = await buildFormsPlugin(options.forms)(config)
|
||||
// submitForm reads it from payload.config when the call doesn't pass one
|
||||
if (options.forms.consentFieldName) {
|
||||
config.custom = { ...config.custom, ipal: { ...config.custom?.ipal, consentFieldName: options.forms.consentFieldName } }
|
||||
}
|
||||
}
|
||||
|
||||
// --- globals ---
|
||||
|
||||
+14
-10
@@ -62,7 +62,11 @@ export type IpalOptions = {
|
||||
*/
|
||||
content?: ContentOption
|
||||
|
||||
/** Disable the plugin without uninstalling (keeps DB schema intact) */
|
||||
/**
|
||||
* `false` = plugin off without uninstalling: its collections, globals and
|
||||
* fields stay (DB schema and migrations unchanged), but it adds no endpoints,
|
||||
* onInit work or admin components.
|
||||
*/
|
||||
enabled?: boolean
|
||||
|
||||
/**
|
||||
@@ -71,6 +75,15 @@ export type IpalOptions = {
|
||||
*/
|
||||
forms?: FormsOption
|
||||
|
||||
/**
|
||||
* Change any of the plugin's globals (site-settings, site-integrations,
|
||||
* cookie-settings, notifications): an object merges over the plugin's
|
||||
* (`access` / `admin` / `hooks` key by key, your keys win), a function gets
|
||||
* the global and returns the one to use. E.g. let any logged-in user edit
|
||||
* Notifications: `{ notifications: { access: { update: authenticated } } }`.
|
||||
*/
|
||||
globalOverrides?: GlobalOverrides
|
||||
|
||||
i18n: I18nConfig
|
||||
|
||||
/**
|
||||
@@ -90,15 +103,6 @@ export type IpalOptions = {
|
||||
*/
|
||||
pages?: PagesOption
|
||||
|
||||
/**
|
||||
* Change any of the plugin's globals (site-settings, site-integrations,
|
||||
* cookie-settings, notifications): an object merges over the plugin's
|
||||
* (`access` / `admin` / `hooks` key by key, your keys win), a function gets
|
||||
* the global and returns the one to use. E.g. let any logged-in user edit
|
||||
* Notifications: `{ notifications: { access: { update: authenticated } } }`.
|
||||
*/
|
||||
globalOverrides?: GlobalOverrides
|
||||
|
||||
/**
|
||||
* next/cache `revalidatePath`, INJECTED (the plugin never imports next/cache).
|
||||
* When given, saving any of the plugin's globals (Site Settings, Site
|
||||
|
||||
Reference in New Issue
Block a user