Creating an editorial workflow with content moderation
Many organizations have an editorial workflow that must be followed before content can be published on the website. The Content Moderation
module allows content created in Drupal to go through an editorial process before it is published. In this recipe, we will create a content moderation workflow that puts content in a draft state and then reviews, approves, and publishes it. The content remains in a draft state and is hidden from site visitors until it is published.
Getting ready
In this recipe, we will be using the standard installation, which provides the Article content type. Any content type will suffice.
How to do it…
- Begin by installing the
Content Moderation
module and its dependent module,Workflows
:php vendor/bin/drush en content_moderation –yes
- Visit Configuration and then Workflows. This page lists all configured content moderation workflows. Click Add workflow to create a new workflow.
- In the Label field, give it a label of Approval workflow and select Content moderation for Workflow type.
- The workflow has two default states of Draft and Published. We need to add Review and Approval states. For each of our new states, click the Add a new state link. Fill in the State label and press Save. Leave the Published and Default revision checkboxes unchecked. Those should only be used for a published state.
- Rearrange the states’ ordering so that it is Draft, Review, Approval, Published. Press Save at the bottom of the form so that our ordering is saved.
- Next, we need to create a transition to move a Draft to Review. Click Add a new transition. Set the Transition label to Ready for review. Select Draft as a From state. Then, select Review as the To state and press Save.
- Now, we will create the Review to Approval transition. Click Add a new transition. Set the Transition label to Needs approval. Select Review as a From state. Then, select Approval as the To state and press Save.
- We must edit the default Publish transition. Uncheck Draft from the From checkboxes and select Approval.
- Finally, we must assign this workflow to content entities. Under This workflow applies to, look for Content types. Press Select and a dialog will open. Check Article, then press Save in the dialog.
- Press Save at the bottom of the form. Our content moderation workflow is now complete!
How it works…
Without Content Moderation
, publishable content entities only have two states: unpublished or published. There also are no permissions to control who can make an unpublished piece of content published or vice versa. Content Moderation
solves this problem.
The Workflows
module provides an API for defining states and transitions. It is up to modules such as Content Moderation
to provide Workflow Type plugins to bring meaningful functionality. The Content Moderation
module integrates with the revision capabilities of Drupal content entities.
When editing a content entity that uses Content Moderation
, there will be a Moderation State field. This field contains the states that a piece of content can transition to, based on the current user’s permissions.
See also
- Content Moderation module documentation on Drupal.org: https://www.drupal.org/docs/8/core/modules/content-moderation/overview
- Workflows module documentation on
Drupal.org
: https://www.drupal.org/docs/8/core/modules/workflows/overview