Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.38 KB

usage-with-custom-publish.md

File metadata and controls

50 lines (38 loc) · 1.38 KB

Usage with Document Actions

Manual publish implementation

In some cases you may already have a custom publish action defined for your studio. In this scenario the plugin may not work as expected as documents could be missing the language fields.

In order to get the full functionality, you can make use of the updateIntlFieldsForDocument function. This is also used internally in the plugin's custom publish action.

Example:

import {updateIntlFieldsForDocument} from '@sanity/document-internationalization/lib/utils'

export const CustomPublishAction = ({id, type, onComplete}) => {
  const {publish} = useDocumentOperation(id, type)

  return {
    onHandle: async () => {
      publish.execute()
      await updateIntlFieldsForDocument(id, type)
      if (onComplete) onComplete()
    },
  }
}

Add additional actions

It is also possible to import all actions "as-is" from the package to add to your actions resolver.

Example:

import {
  PublishWithi18nAction,
  DeleteWithi18nAction,
  DuplicateWithi18nAction,
} from '@sanity/document-internationalization/lib/actions'
import defaultResolve from 'part:@sanity/base/document-actions'

// @README https://www.sanity.io/docs/document-actions
export default function resolveDocumentActions(props) {
  return [
    ...defaultResolve(props),
    PublishWithi18nAction,
    DeleteWithi18nAction,
    DuplicateWithi18nAction,
  ]
}