Erste brauchbare Version
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { type CollectionConfig } from 'payload';
|
||||
import { lexicalEditor, UploadFeature } from '@payloadcms/richtext-lexical';
|
||||
|
||||
export const Posts: CollectionConfig = {
|
||||
slug: 'posts',
|
||||
|
||||
labels: {
|
||||
singular: 'Artikel',
|
||||
plural: 'Artikel'
|
||||
},
|
||||
|
||||
admin: {
|
||||
useAsTitle: 'title',
|
||||
group: 'Inhalte',
|
||||
description: 'Artikel verwalten',
|
||||
defaultColumns: [ 'id', 'slug', 'title', 'author', '_status' ],
|
||||
hideAPIURL: true,
|
||||
preview: doc =>
|
||||
`${process.env.NEXT_PUBLIC_PAYLOAD_URL}/post/${doc.slug}/?preview`
|
||||
},
|
||||
|
||||
versions: {
|
||||
drafts: true
|
||||
},
|
||||
|
||||
access: {
|
||||
read: ({ data, req }) => (data?._status && data?._status !== 'draft') || [ 'admin', 'superadmin' ].includes(req.user?.role),
|
||||
create: ({ req }) => [ 'admin', 'superadmin' ].includes(req.user?.role),
|
||||
update: ({ req }) => [ 'admin', 'superadmin' ].includes(req.user?.role),
|
||||
delete: ({ req }) => [ 'admin', 'superadmin' ].includes(req.user?.role)
|
||||
},
|
||||
|
||||
orderable: true,
|
||||
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Titel',
|
||||
type: 'text',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'slug',
|
||||
label: 'Slug',
|
||||
type: 'text',
|
||||
required: true,
|
||||
unique: true,
|
||||
admin: {
|
||||
placeholder: 'Zum Beispiel: mein-toller-post'
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'content',
|
||||
label: 'Inhalt',
|
||||
type: 'richText',
|
||||
editor: lexicalEditor({
|
||||
features: ({ defaultFeatures }) => [
|
||||
...defaultFeatures,
|
||||
UploadFeature({
|
||||
collections: {
|
||||
media: {
|
||||
fields: []
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
},
|
||||
{
|
||||
name: 'author',
|
||||
label: 'Autor',
|
||||
type: 'relationship',
|
||||
relationTo: 'users',
|
||||
filterOptions: () => {
|
||||
return {
|
||||
// eslint-disable-next-line camelcase
|
||||
role: { not_equals: 'superadmin' }
|
||||
};
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
Reference in New Issue
Block a user