Hooks
Create a new file in the @/plugins/custom/hooks directory,
import defineHook from '@/lib/hook/defineHook.js'
export default defineHook({
id: 'sendMailForMessage',
filter: 'record:write',
resolve: async (
ctx,
{ type, changes, record, recordTypeId }
) => {
if (recordTypeId !== 'message') return
if (type !== 'create') return
const fields = await sendMailForMessage(ctx, { record })
return fields
}
})
Then within the @/plugins/custom/hooks/index.js
import sendMailForMessage from './sendMailForMessage'
export default ([
sendMailForMessage
])
The hooks are registered within @/plugins/custom/register.js
import definePlugin from '@/lib/module/definePlugin'
import hooks from './hooks'
export default definePlugin({
hooks
})
Roadmap
- Ability to define hooks on the Record Type level. This allows for encapsulated logic. Which should be the main usage. For now global hooks will suffice.