The ability to create content is one of the key responsibilities of any CMS. The content-creator plugin type is one way Tina lets you add this behaviour.

content-creator-plugin-tinacms

Interface

interface ContentCreatorPlugin<FormShape> {
  __type: 'content-creator'
  name: string
  fields: Field[]
  onSubmit(value: FormShape, cms: CMS): Promise<void> | void
  actions?: FormOptions<any>['actions']
  buttons?: FormOptions<any>['buttons']
  reset?: FormOptions<any>['reset']
  onChange?: FormOptions<any>['onChange']
}
OptionDescription
__typeThe name of the plugin. Always 'content-creator'.
nameThe text to be displayed in the "Add Content" menu.
fieldsAn array of fields that populate a modal form. Field values can populate new file data.
onSubmitA function that creates content. Called once the form is submitted.
actionsOptional: An array of custom actions that will be added to the form.
buttonsOptional: An object to customize the 'Save' and 'Reset' button text for the form.
resetOptional: A function that runs when the form state is reset by the user via the 'Reset' button.
onChangeOptional: A function that runs when the form values are changed.

Examples

Building a ContentCreatorPlugin

const BlogPostCreatorPlugin = {
  __type: 'content-creator',
  fields: [
    {
      label: 'Title',
      name: 'title',
      component: 'text',
      validation(title) {
        if (!title) return 'Required.'
      },
    },
    {
      label: 'Date',
      name: 'date',
      component: 'date',
      description: 'The default will be today.',
    },
    {
      label: 'Author',
      name: 'author_name',
      component: 'text',
      description: 'Who wrote this, yo?',
    },
  ],
  onSubmit(values, cms) {
    // Call functions that create the new blog post. For example:
    cms.apis.someBackend.createPost(values)
  },
}

After registering the plugin with the CMS it will be accessible.

cms.plugins.add(BlogPostCreatorPlugin)

Further Reading

Last Edited: March 16, 2021