In addition to all the render<LOCATION>
hooks, the SDK also exposes a number of hooks that can be useful to intercept specific events happening on the interface, and execute custom code, or change the way the regular interface behaves.
All these event hooks follow the same on<EVENT>
naming convention.
Execute custom code when the plugin loads up There are situations where a plugin needs to execute code as soon as the DatoCMS interface is loaded. For example, a plugin may need to contact third party systems to verify some information, or maybe notify the user in some way.
In these scenarios you can use the onBoot
hook, and have the guarantee that it will be called as soon as the main DatoCMS application is loaded:
import { connect } from 'datocms-plugin-sdk' ;
connect ( {
async onBoot ( ctx ) {
ctx . notice ( 'Hi there!' ) ;
}
} ) ;
Inside this hook there is no point in rendering anything, because it won't be displayed anywhere. For a concrete use case of this hook, please have a look at the chapter Releasing new plugin versions .
Intercept actions on records Another useful group of event hooks can be used to intercept when the user wants to perform a specific action on one (or multiple) records:
All these hooks can return the value false
to stop the relative action from happening.
In the following example we're using the onBeforeItemUpsert
hook to check if the user is saving articles with the "highlighted" flag turned on, and if that's the case we show them an additional confirmation, to make sure they know what they're doing:
import { connect } from 'datocms-plugin-sdk' ;
connect ( {
async onBeforeItemUpsert ( createOrUpdateItemPayload , ctx ) {
const item = createOrUpdateItemPayload . data ;
const articleItemTypeId = Object . values ( ctx . itemTypes ) . find ( itemType => itemType . attributes . api_key === 'article' ) . id ;
if ( item . relationships . item_type . data . id !== articleItemTypeId ) {
return ;
}
if ( ! item . attributes . highlighted ) {
return ;
}
const confirmation = await ctx . openConfirm ( {
title : 'Mark Article as highlighted?' ,
content : 'Highlighted articles are displayed on the homepage of the site!' ,
cancel : { label : 'Cancel' , value : false } ,
choices : [
{ label : 'Yes, save as highlighted' , value : true , intent : 'negative' } ,
] ,
} ) ;
if ( ! confirmation ) {
ctx . notice ( 'The article has not been saved, you can unflag the "highlighted" field.' ) ;
return false ;
}
}
} ) ;
We can also do something similar to confirm if the user really wants to publish a record. The onBeforeItemsPublish
hook is also called when the user is selecting multiple records from the collection page, and applying a batch publish operation:
import { connect } from 'datocms-plugin-sdk' ;
connect ( {
async onBeforeItemsPublish ( items , ctx ) {
return await ctx . openConfirm ( {
title : ` Publish ${ items . length } records? ` ,
content : ` This action will make the records visibile on the public website! ` ,
cancel : { label : 'Cancel' , value : false } ,
choices : [ { label : 'Yes, publish' , value : true } ] ,
} ) ;
}
} ) ;
onBoot
This function will be called once at boot time and can be used to perform
ie. some initial integrity checks on the configuration.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBeforeItemsDestroy
This function will be called before destroying records. You can stop the
action by returning false
.
Return value The (optionally async) function must return a boolean.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBeforeItemsPublish
This function will be called before publishing records. You can stop the
action by returning false
.
Return value The (optionally async) function must return a boolean.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBeforeItemsUnpublish
This function will be called before unpublishing records. You can stop the
action by returning false
.
Return value The (optionally async) function must return a boolean.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBeforeItemUpsert
This function will be called before saving a new version of a record. You
can stop the action by returning false
.
Return value The (optionally async) function must return a boolean.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBoot
This function will be called once at boot time and can be used to perform
ie. some initial integrity checks on the configuration.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBeforeItemsDestroy
This function will be called before destroying records. You can stop the
action by returning false
.
Return value The (optionally async) function must return a boolean.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBeforeItemsPublish
This function will be called before publishing records. You can stop the
action by returning false
.
Return value The (optionally async) function must return a boolean.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBeforeItemsUnpublish
This function will be called before unpublishing records. You can stop the
action by returning false
.
Return value The (optionally async) function must return a boolean.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
onBeforeItemUpsert
This function will be called before saving a new version of a record. You
can stop the action by returning false
.
Return value The (optionally async) function must return a boolean.
Properties available in context The following information and methods are available:
ctx.account The account that is the project owner.
ctx.currentRole The role for the current DatoCMS user.
ctx.currentUser The current DatoCMS user. It can either be the owner or one of the
collaborators (regular or SSO).
ctx.currentUserAccessToken The access token to perform API calls on behalf of the current user. Only
available if currentUserAccessToken additional permission is granted.
ctx.environment The ID of the current environment.
ctx.fields All the fields currently loaded for the current DatoCMS project, indexed by
ID. It will always contain the current model fields and all the fields of
the blocks it might contain via Modular Content/Structured Text fields. If
some fields you need are not present, use the loadItemTypeFields function
to load them.
ctx.fieldsets All the fieldsets currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current model fields and all the fields
of the blocks it might contain via Modular Content/Structured Text fields.
If some fields you need are not present, use the loadItemTypeFieldsets
function to load them.
ctx.itemTypes All the models of the current DatoCMS project, indexed by ID.
ctx.owner The account that is the project owner.
ctx.plugin The current plugin.
ctx.site The current DatoCMS project.
ctx.ssoUsers All the SSO users currently loaded for the current DatoCMS project, indexed
by ID. It will always contain the current user. If some users you need are
not present, use the loadSsoUsers function to load them.
ctx.theme An object containing the theme colors for the current DatoCMS project.
ctx.ui UI preferences of the current user (right now, only the preferred locale is
available).
ctx.users All the regular users currently loaded for the current DatoCMS project,
indexed by ID. It will always contain the current user. If some users you
need are not present, use the loadUsers function to load them.
Methods available in context The following information and methods are available:
ctx.alert() Triggers an "error" toast displaying the selected message.
ctx.createNewItem() Opens a dialog for creating a new record. It returns a promise resolved
with the newly created record or null if the user closes the dialog
without creating anything.
ctx.customToast() Triggers a custom toast displaying the selected message (and optionally a
CTA).
ctx.editItem() Opens a dialog for editing an existing record. It returns a promise
resolved with the edited record, or null if the user closes the dialog
without persisting any change.
ctx.editUpload() Opens a dialog for editing a Media Area asset. It returns a promise
resolved with:
The updated asset, if the user persists some changes to the asset itself
null, if the user closes the dialog without persisting any change
An asset structure with an additional deleted property set to true, if
the user deletes the asset.
ctx.editUploadMetadata() Opens a dialog for editing a "single asset" field structure. It returns a
promise resolved with the updated structure, or null if the user closes
the dialog without persisting any change.
ctx.loadFieldsUsingPlugin() Loads all the fields in the project that are currently using the plugin for
one of its manual field extensions.
ctx.loadItemTypeFields() Loads all the fields for a specific model (or block). Fields will be
returned and will also be available in the the fields property.
ctx.loadItemTypeFieldsets() Loads all the fieldsets for a specific model (or block). Fieldsets will be
returned and will also be available in the the fieldsets property.
ctx.loadSsoUsers() Loads all SSO users. Users will be returned and will also be available in
the the ssoUsers property.
ctx.loadUsers() Loads all regular users. Users will be returned and will also be available
in the the users property.
ctx.navigateTo() Moves the user to another URL internal to the backend.
ctx.notice() Triggers a "success" toast displaying the selected message.
ctx.openConfirm() Opens a UI-consistent confirmation dialog. Returns a promise resolved with
the value of the choice made by the user.
ctx.openModal() Opens a custom modal. Returns a promise resolved with what the modal itself
returns calling the resolve() function.
ctx.selectItem() Opens a dialog for selecting one (or multiple) record(s) from a list of
existing records of type itemTypeId. It returns a promise resolved with
the selected record(s), or null if the user closes the dialog without
choosing any record.
ctx.selectUpload() Opens a dialog for selecting one (or multiple) existing asset(s). It
returns a promise resolved with the selected asset(s), or null if the
user closes the dialog without selecting any upload.
ctx.updateFieldAppearance() Performs changes in the appearance of a field. You can install/remove a
manual field extension, or tweak their parameters. If multiple changes are
passed, they will be applied sequencially.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.
ctx.updatePluginParameters() Updates the plugin parameters.
Always check ctx.currentRole.meta.finalpermissions.canedit_schema
before calling this, as the user might not have the permission to perform
the operation.