#Syncing publish status with payload-workflow plugin

5 messages · Page 1 of 1 (latest)

heavy shuttle
#

@iron hazel thanks for answering in the other thread, I'm making it into a separate one instead of messaging you directly so we keep it public in case other people are looking for this!

The reason why there's a different status column for the workflows is because I can't customise the published / draft statuses within Payload. If you want to sync the published status with the workflow status I'd suggest you use hooks (https://payloadcms.com/docs/hooks/collections)

So for example: Within a hook you look for any changes in the "workflowStatus" field, if the workflowStatus has reached for example "Published", you update the publishedStatus (the one provided by Payload) to "published" as well.

as you mentioned, we were able to sync the workflow status using hooks and that works fine, but now we're in a situation where if something is already published via the workflow and we try to unpublish via the regular Payload mechanisms (clicking the "Publish" button in the collection or the "Unpublish" link underneath) we don't get any updates and the entity remains published. I'm guessing this is due to not being able to customise the behaviour of the Payload buttons to hook them to the workflow status as well, right? do you have any suggestions?

Payload CMS

Payload is a headless CMS and application framework built with TypeScript, Node.js, React and MongoDB

coral zealotBOT
iron hazel
# heavy shuttle <@203164998514638848> thanks for answering in the other thread, I'm making it in...

Hi @heavy shuttle, sorry for the late response. butt....

You can do the same thing when un-publishing a document within payload, unpublishing also triggers a afterChange hook where you can detect if the document is still published. From there you can update the field workflowStatus to the status you want it to be on in the workflow when it get's unpublished.

If you need some concrete example, I can setup a little example repo / snippet if you want 🙂

#

Now that you mention it, it might be a good idea to include such examples (or even a built in syncing option) within the payload-workflow project

heavy shuttle
#

thanks for the response, @iron hazel! we've been trying to do everything in the beforeChange hook, but I'll try to split the logic. would really appreciate an example snippet though, we just started on Payload and still not super familiar with the hooks. and I agree that it could be a good idea to add these to the repo, since I would assume most people would try to do some sort of syncing between both systems. I've seen that's sort of on the roadmap in the README, but in my opinion just having code examples could suffice for now!