init commit for iPAL-kit plugin
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import type { Field, RelationshipField } from 'payload'
|
||||
|
||||
import type { PagesOption, SystemPageRole } from './types.js'
|
||||
|
||||
import { ALL_SYSTEM_PAGE_ROLES } from './types.js'
|
||||
|
||||
/** Admin-facing labels per role. */
|
||||
const ROLE_LABELS: Record<SystemPageRole, string> = {
|
||||
cookiePolicy: 'Cookie Policy',
|
||||
homepage: 'Homepage',
|
||||
privacyPolicy: 'Privacy Policy',
|
||||
}
|
||||
|
||||
/** Admin descriptions per role. */
|
||||
const ROLE_DESCRIPTIONS: Record<SystemPageRole, string> = {
|
||||
cookiePolicy: 'Page linked from the cookie consent banner.',
|
||||
homepage: 'Page served at the locale root (e.g. /pl, /en).',
|
||||
privacyPolicy: 'Page linked as the privacy policy.',
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds one relationship field per configured system-page role.
|
||||
*
|
||||
* Each field points at the client's Pages collection (via the provided slug)
|
||||
* and holds a single document reference. The referenced document's slug is
|
||||
* localized, so the same assignment resolves to /pl/strona-glowna and
|
||||
* /en/home at runtime — role assignment is locale-agnostic, path resolution
|
||||
* is locale-aware (see getSystemPagePath).
|
||||
*/
|
||||
export function buildSystemPagesFields(pages: PagesOption): Field[] {
|
||||
const roles = pages.roles?.length ? pages.roles : [...ALL_SYSTEM_PAGE_ROLES]
|
||||
|
||||
return roles.map((role): RelationshipField => ({
|
||||
name: role,
|
||||
type: 'relationship',
|
||||
admin: {
|
||||
description: ROLE_DESCRIPTIONS[role],
|
||||
},
|
||||
label: ROLE_LABELS[role],
|
||||
maxDepth: 1,
|
||||
relationTo: pages.slug,
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user