@websolutespa/payload-plugin-bowl
Version:
Bowl PayloadCms plugin of the BOM Repository
82 lines (81 loc) • 2.8 kB
JavaScript
import { isObject } from '@websolutespa/bom-core';
import { isRole } from '../core';
import { roles } from '../types';
export const Locale = (options)=>({
type: 'withGlobal',
slug: options.slug.locale,
admin: {
group: options.group.config
},
access: {
update: isRole(roles.Admin)
},
hooks: {
afterRead: [
async ({ doc, req, findMany })=>{
doc = doc || {};
const newDoc = doc.items ? doc : {
items: [],
globalType: 'locale'
};
newDoc.items = options.locales.map((locale)=>{
const defaultItem = isObject(locale) ? {
...locale,
id: locale.code,
isActive: true
} : {
id: locale,
code: locale,
isActive: true
};
const item = Object.assign(defaultItem, newDoc.items.find((x)=>x.id === locale) || {});
item.isDefault = locale === options.defaultLocale;
return item;
});
return newDoc;
}
]
},
fields: [
{
name: 'items',
type: 'array',
minRows: options.locales.length,
maxRows: options.locales.length,
required: true,
admin: {
components: {
RowLabel: '@websolutespa/payload-plugin-bowl/client#LocaleRowLabel'
}
},
fields: [
{
name: 'id',
type: 'relationship',
relationTo: options.slug.language,
required: true,
admin: {
readOnly: true
}
},
{
type: 'withIsActive',
required: true
},
{
type: 'withIsDefault',
required: true,
admin: {
readOnly: true
}
},
{
type: 'withCheckbox',
name: 'isHidden',
required: true
}
]
}
]
});
//# sourceMappingURL=Locale.js.map