Urvashi Bangdel Rai
Hello World!
Code examples using document.newDocumentOptions to hide the Create new document button at the structure level and/or disable it in the global create menu.
document: {
newDocumentOptions: (prev, { currentUser, creationContext }) => {
if (creationContext.type === 'structure') {
return [];
}
return prev;
},
},
document: {
newDocumentOptions: (prev, { currentUser, creationContext }) => {
const { type, schemaType } = creationContext;
if (type === 'structure' && schemaType == 'pet') {
return [];
}
return prev;
},
},
document: {
newDocumentOptions: (prev, { currentUser, creationContext }) => {
const { type, schemaType } = creationContext;
if (
type === 'structure' &&
currentUser?.roles.find((role) => role.name === 'editor')
) {
return [];
}
return prev;
},
},
document: {
newDocumentOptions: (prev, { currentUser, creationContext }) => {
const { type, schemaType } = creationContext;
if (
type === 'global' &&
currentUser?.roles.find((role) => role.name === 'editor')
) {
return [];
}
return prev;
},
},
document: {
newDocumentOptions: (prev, { currentUser, creationContext }) => {
const { type, schemaType } = creationContext;
if (type === 'global') {
return prev.filter((template) => template.templateId !== 'pet');
}
return prev;
},
},
document: {
newDocumentOptions: (prev, { currentUser, creationContext }) => {
const { type, schemaType } = creationContext;
if (
type === 'global' &&
currentUser?.roles.find((role) => role.name === 'editor')
) {
return prev.filter((template) => template.templateId !== 'pet');
}
return prev;
},
},
document.newDocumentOptions
enables configuring templates for new documents that can be reactive to contextual information, such as the currently logged-in user.
This article features code examples that show how to use document.newDocumentOptions
to hide the Create new document button at the structure level, or to disable it in the global create menu.
You can show or hide the creation option depending on conditional options such as schema type, current user role, structure/global menu, and so on.
Hello World!
Frontend Developer at Sanity.io
The Web and Stuff.
A code snippet to create a custom '+ Add item' button to add items to the top of an array.
Go to Add items to top of array with custom '+ Add item' button