For Drupal projects I’ve always used the comprehensive suite of tools provided by Workbench. But when I started a new project and saw that Workflow is hopefully making it’s way into core it felt like a good time to try it out. One part of the project was the addition of notifications when Workflow states were changed. With the Rules module also receiving lots of attention I decided combining the two modules was the best approach.
The following example was made using Drupal 8.4.4
Enable the Modules #
First of all we have to enable the Workflows module and the Content Moderation module. Click on Extend form the admin menu or go to /admin/modules and find these two modules.
When enabling Content Moderation you will be warned that it is an experimental module. https://www.drupal.org/core/experimental
Edit the Workflow #
If you go to /admin/config/workflow/workflows you will see we have one workflow called Editorial.
Click the Edit button to go to /admin/config/workflow/workflows/manage/editorial
We currently have three states but we want to add a new one for Review. Click the Add a new state link. On the Add state page all we need to enter is a label of Review and then click Save.
Back on the Edit Editorial Workflow page drag the Review state to in between Draft and Published and then click the Save button at the bottom of the page.
We now need to edit the transitions to allow the flow between draft, review and publish. This is how the transitions look by default. We need to enable a draft to be become a review and a review to become published. We want to cut out the draft to published transition.
Below are the default transitions, we’ll first add our new ones and then modify the existing ones.
Click the Add a new transition link and you will be on a page with options for Label, From and To. Set the Label to Review, From to Draft and To as Review then click Save.
Back on the main page drag the new Review transition up so it is between Create New Draft and Publish and then click Save.
We now need to update the existing transitions. Change the Create New Draft From value. It is currently Draft, Published and we need it to be Draft, Review.
Lastly for transitions change the Publish transitions’s From value to Review, Publish. This means a node has to go from Draft to Review before it can be published.
Add The Workflow to Entities #
The last part of the workflow setup is to enable it for any required content types or entities. At the bottom of the page there is the section This Workflow Applies To. In this example we will enable this workflow for Basic Pages.
Click the Select button beside Content types, select Basic Page from the overlay and then click Save. Now If you go to add a Basic Page you will see at the bottom there is a select where you can choose the State of you node.
In the next part we will look at sending email notifications when the Workflow state changes using the Rules module.