I am building a plugin and want to run a bunch of operations in onBoot,
but only if the current user is editing a specific record type.
Something on the like of
async onBoot(ctx) {
if (ctx.currentRecordType !== 'specificRecordType') {
return;
}
// a bunch of operations here
.......
}
Is this possible to do somehow? I couldn’t find anything in the documentation.
Alternatively, is there another event hook similar to onBoot where I can get that information?
Would a Form Outlet work for your needs? That lives at the record level instead of the UI level, and can be triggered only on specific models: Form outlets — DatoCMS
I assumed that Form Outlet was to be used when you wanted to render something at top of the page.
Is it appropriate to use itemFormOutlets to just fetch data and initialise few variables?
Example in (pseudo)code below:
let records = [];
....
connect({
itemFormOutlets(model: ModelBlock, ctx: IntentCtx) {
if (ctx.currentRecordType !== 'specificRecordType') {
return;
}
const client = buildClient({
environment: ctx.environment,
apiToken: ctx.currentUserAccessToken
});
// We'll be building up an array of all records using an AsyncIterator, `client.items.listPagedIterator()`
for await (const record of client.items.listPagedIterator({
filter: { type: "specificRecordType" },
nested: true,
})) {
records.push(record);
}
},
....
onBeforeItemUpsert(ctx) {
//do something with records
}
});
.....