Override Publish changes button + Return all drafts

default discord avatar
adam-mroziklast year
1 1

Hey,

I couldn't locate any info on this. Is there option to override Publish changes button functionality?

Second question: Can I query DB for all draft documents? I saw preview function that can send whole draft to the frontend, but I would like users to be able to save like ~10 different drafts and sort of preview all of them. Is that possible?

Third question: Is there a way to batch publish multiple documents together?

  • Selected Answer
    discord user avatar
    jmikrut
    last year

    Hey @adam-mrozik — good question!

    1. Overriding the Publish changes button is currently not possible, but it would be a great addition. We would accept a PR to add this functionality for sure. It would just function like how swapping in a custom component works now - except you'd swap in your own Publish button. Would be cool. Can I ask what you're looking to do with this?
    2. Yes, you can, although I think there's a bit more that we should think through here. What are you trying to do? Finding all pages that have never been published is easy - just use where: { _status: { equals: 'draft' } }. But that will not send back pages that have been published, but have newer drafts available. To get both all pages that have never been published, as well as all pages that have newer drafts available, you would need to use the draft: true argument and then filter the results manually in your app(s).
    3. To batch publish multiple documents together, you could write a script that fetches all draft documents and then loops over them to change each one's _status to 'published', but that would need to be a script. There is no endpoint operation available for this but it could be easily done with a custom endpoint or script.

    How's that?

    1 reply
  • default discord avatar
    adam-mroziklast year

    Wow, Thanks for very quick answers!

    Just for the context:

    1. I want internal employees be able to publish changes to prod with this button, so I wanted to add some safety checks (e.g. is appropriate version of PROD frontend deployed for the given payload cms version, or add some additional safety pop-up like are you sure you want to deploy document to PROD?.
    2. I imagine internal employees might want to change multiple documents and see how it all looks together. I wanted to make it so that Save Draft saves the document and makes it visible on Staging website, while Publish Change would push data to to the PROD website. This way I can have only one Payload CMS and one place for internal employees to edit documents and also publish them to the default site.
    3. Nice! So just a custom button would suffice here, thanks!
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.